home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 4 / United Public Domain Gold 4.iso / fredfish / ff.0355.dms / ff.0355.adf / ImageEditor / im24.c < prev    next >
C/C++ Source or Header  |  1990-06-12  |  82KB  |  2,694 lines

  1.  
  2.  /*
  3.   * im24.c
  4.   *
  5.   * (c) 1990 by Robert Junghans
  6.   *
  7.   * image/sprite-editor for programmers
  8.   *
  9.   */
  10.  
  11.  /* needed aztec-includes: */
  12. #include <functions.h>
  13.  
  14.  /* some patterns to make the source shorter: */
  15. #define PTT1 GADGHCOMP,RELVERIFY,BOOLGADGET
  16. #define PTT2 50,19,PTT1,(APTR)&bor1,NULL
  17. #define PTT3 100,12,PTT1,(APTR)&bor2,NULL
  18.  
  19. #define no_msg(a) (msg=(struct IntuiMessage *)GetMsg(a->UserPort))==NULL
  20.  
  21.  /* library-base-pointer: */
  22. struct GfxBase *GfxBase=NULL;
  23. struct IntuitionBase *IntuitionBase=NULL;
  24.  
  25.  /* some vars for intuition: */
  26. struct Screen *scr=NULL;
  27. struct ViewPort *vp;
  28. struct Window *win1=NULL,*win2=NULL,*win3=NULL,*win4,*win5=NULL,*win6,*win7,
  29.               *win8=NULL,*win9,*win10,*win11,*win12=NULL,*win13,*win14,
  30.               *win15,*win16,*win17;
  31. struct RastPort *rp1,*rp2,*rp3,*rp4,*rp5,*rp6,*rp7,*rp8,*rp9,*rp10,*rp11,
  32.                 *rp12,*rp13,*rp14,*rp15,*rp16,*rp17;
  33. UWORD bline;
  34.  
  35. struct IntuiMessage *msg;
  36. long sig;
  37. ULONG class;
  38. USHORT code,id;
  39. struct Gadget *gad;
  40. SHORT xpos,ypos;
  41.  
  42.  /* vars for disk operations: */
  43. struct BitMap bmap;
  44. struct FileHandle *fh=NULL;
  45. char name[30];
  46.  
  47.  /* text-array to be saved as source-code: */
  48. char src[44][58][4];
  49.  
  50.  /* counter etc.: */
  51. int i,j,k,nr,xnr,ynr,end;
  52. char buchst;
  53.  
  54.  /* settings: */
  55. int colorl=1,colorr=0,anzeigen=0,xmin=5,ymin=12,xmax=502,ymax=185,bitmaps=4,
  56.     aufl=1;
  57. long breite=166,hoehe=58;
  58.  
  59.  /* the backup- and the user-palette: */
  60. UWORD paletteb[]={
  61.     0x000,0xfff,0xd00,0xf60,0xff0,0x7f7,0x0d0,0x091,
  62.     0x777,0xbbb,0x4df,0x09f,0x00c,0x80a,0xc0d,0xf0f},
  63.       paletteu[16];
  64.  
  65.  /* my special mouse pointer: */
  66. USHORT mousedata[]={
  67.     0x0000,0x0000,0x0500,0x0600,0x0500,0x0600,0x0500,0x0700,0x0880,0x0f80,
  68.     0x1040,0x1880,0xe038,0xf058,0x0000,0xf078,0xe038,0x3040,0x1040,0x1880,
  69.     0x0880,0x0700,0x0500,0x0200,0x0500,0x0600,0x0500,0x0600,0x0000,0x0000};
  70. USHORT (*mouseptr)[]=NULL;
  71.  
  72.  /* the standard-80-font: */
  73. struct TextAttr font={
  74.     (STRPTR)"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT};
  75.  
  76.  /* now the 'Kraut und Rueben'-part: */
  77. SHORT pos1[]={-1,-1,50,-1,50,19,-1,19,-1,-1},
  78.       pos2[]={0,0,99,0,99,11,0,11,0,0},
  79.       pos3[]={0,0,122,0,122,9,0,9,0,0};
  80.  
  81. struct Border bor1={0,0,1,0,JAM1,5,pos1,NULL},
  82.               bor2={0,0,1,0,JAM1,5,pos2,NULL},
  83.               bor3={-1,-1,1,0,JAM1,5,pos3,NULL};
  84.  
  85. struct IntuiText text1={1,0,JAM1,41,0,NULL,(UBYTE *)"i",NULL},
  86.                  text2={1,0,JAM1,9,11,NULL,(UBYTE *)"icon",&text1},
  87.                  text3={1,0,JAM1,9,11,NULL,(UBYTE *)"info",NULL},
  88.                  text4={1,0,JAM1,41,0,NULL,(UBYTE *)"f",NULL},
  89.                  text5={1,0,JAM1,5,11,NULL,(UBYTE *)"flood",&text4},
  90.                  text6={1,0,JAM1,41,0,NULL,(UBYTE *)"u",NULL},
  91.                  text7={1,0,JAM1,9,11,NULL,(UBYTE *)"undo",&text6},
  92.                  text8={1,0,JAM1,41,0,NULL,(UBYTE *)"d",NULL},
  93.                  text9={1,0,JAM1,9,11,NULL,(UBYTE *)"disk",&text8},
  94.                  text10={1,0,JAM1,41,0,NULL,(UBYTE *)"c",NULL},
  95.                  text11={1,0,JAM1,1,11,NULL,(UBYTE *)"colors",&text10},
  96.                  text12={1,0,JAM1,41,0,NULL,(UBYTE *)"p",NULL},
  97.                  text13={1,0,JAM1,5,11,NULL,(UBYTE *)"prefs",&text12},
  98.                  text14={1,0,JAM1,41,0,NULL,(UBYTE *)"e",NULL},
  99.                  text15={1,0,JAM1,1,11,NULL,(UBYTE *)"extras",&text14},
  100.  
  101.                  text16={1,0,JAM1,34,2,NULL,(UBYTE *)"o.k.",NULL},
  102.  
  103.                  text17={1,0,JAM1,41,0,NULL,(UBYTE *)"s",NULL},
  104.                  text18={1,0,JAM1,9,11,NULL,(UBYTE *)"show",&text17},
  105.                  text19={1,0,JAM1,41,0,NULL,(UBYTE *)"c",NULL},
  106.                  text20={1,0,JAM1,5,11,NULL,(UBYTE *)"clear",&text19},
  107.                  text21={1,0,JAM1,41,0,NULL,(UBYTE *)"h",NULL},
  108.                  text22={1,0,JAM1,1,11,NULL,(UBYTE *)"flip h",&text21},
  109.                  text23={1,0,JAM1,41,0,NULL,(UBYTE *)"v",NULL},
  110.                  text24={1,0,JAM1,1,11,NULL,(UBYTE *)"flip v",&text23},
  111.                  text25={1,0,JAM1,41,0,NULL,(UBYTE *)"u",NULL},
  112.                  text26={1,0,JAM1,13,11,NULL,(UBYTE *)"up1",&text25},
  113.                  text27={1,0,JAM1,13,11,NULL,(UBYTE *)"up2",NULL},
  114.                  text28={1,0,JAM1,13,11,NULL,(UBYTE *)"up3",NULL},
  115.                  text29={1,0,JAM1,41,0,NULL,(UBYTE *)"d",NULL},
  116.                  text30={1,0,JAM1,5,11,NULL,(UBYTE *)"down1",&text29},
  117.                  text31={1,0,JAM1,5,11,NULL,(UBYTE *)"down2",NULL},
  118.                  text32={1,0,JAM1,5,11,NULL,(UBYTE *)"down3",NULL},
  119.                  text33={1,0,JAM1,41,0,NULL,(UBYTE *)"r",NULL},
  120.                  text34={1,0,JAM1,1,11,NULL,(UBYTE *)"right1",&text33},
  121.                  text35={1,0,JAM1,1,11,NULL,(UBYTE *)"right2",NULL},
  122.                  text36={1,0,JAM1,1,11,NULL,(UBYTE *)"right3",NULL},
  123.                  text37={1,0,JAM1,41,0,NULL,(UBYTE *)"l",NULL},
  124.                  text38={1,0,JAM1,5,11,NULL,(UBYTE *)"left1",&text37},
  125.                  text39={1,0,JAM1,5,11,NULL,(UBYTE *)"left2",NULL},
  126.                  text40={1,0,JAM1,5,11,NULL,(UBYTE *)"left3",NULL},
  127.  
  128.                  text41={1,0,JAM1,1,0,NULL,(UBYTE *)"asm",NULL},
  129.                  text42={1,0,JAM1,1,11,NULL,(UBYTE *)"sprite",&text41},
  130.                  text43={1,0,JAM1,1,0,NULL,(UBYTE *)"c",NULL},
  131.                  text44={1,0,JAM1,1,11,NULL,(UBYTE *)"sprite",&text43},
  132.                  text45={1,0,JAM1,41,0,NULL,(UBYTE *)"a",&text41},
  133.                  text46={1,0,JAM1,5,11,NULL,(UBYTE *)"image",&text45},
  134.                  text47={1,0,JAM1,41,0,NULL,(UBYTE *)"c",&text43},
  135.                  text48={1,0,JAM1,5,11,NULL,(UBYTE *)"image",&text47},
  136.                  text49={1,0,JAM1,41,0,NULL,(UBYTE *)"p",NULL},
  137.                  text50={1,0,JAM1,1,0,NULL,(UBYTE *)"pal",&text49},
  138.                  text51={1,0,JAM1,9,11,NULL,(UBYTE *)"ilbm",&text50},
  139.  
  140.                  text52={1,0,JAM1,41,0,NULL,(UBYTE *)"l",NULL},
  141.                  text53={1,0,JAM1,9,11,NULL,(UBYTE *)"ilbm",&text52},
  142.                  text54={1,0,JAM1,41,0,NULL,(UBYTE *)"s",NULL},
  143.                  text55={1,0,JAM1,9,11,NULL,(UBYTE *)"ilbm",&text54},
  144.                  text56={1,0,JAM1,41,0,NULL,(UBYTE *)"1",NULL},
  145.                  text57={1,0,JAM1,5,11,NULL,(UBYTE *)"plane",&text56},
  146.                  text58={1,0,JAM1,41,0,NULL,(UBYTE *)"2",NULL},
  147.                  text59={1,0,JAM1,1,11,NULL,(UBYTE *)"planes",&text58},
  148.                  text60={1,0,JAM1,41,0,NULL,(UBYTE *)"3",NULL},
  149.                  text61={1,0,JAM1,1,11,NULL,(UBYTE *)"planes",&text60},
  150.                  text62={1,0,JAM1,41,0,NULL,(UBYTE *)"4",NULL},
  151.                  text63={1,0,JAM1,1,11,NULL,(UBYTE *)"planes",&text62},
  152.  
  153.                  text64={1,0,JAM1,26,2,NULL,(UBYTE *)"cancel",NULL},
  154.                  text65={1,0,JAM1,26,2,NULL,(UBYTE *)"(o).k.",NULL},
  155.  
  156.                  text66={1,0,JAM1,30,2,NULL,(UBYTE *)"hires",NULL},
  157.                  text67={1,0,JAM1,26,2,NULL,(UBYTE *)"normal",NULL},
  158.                  text68={1,0,JAM1,0,-8,NULL,(UBYTE *)"width :",NULL},
  159.                  text69={1,0,JAM1,0,-8,NULL,(UBYTE *)"height :",NULL},
  160.  
  161.                  text70={1,0,JAM1,30,2,NULL,(UBYTE *)"reset",NULL},
  162.                  text71={1,0,JAM1,-48,1,NULL,(UBYTE *)"red :",NULL},
  163.                  text72={1,0,JAM1,-64,1,NULL,(UBYTE *)"green :",NULL},
  164.                  text73={1,0,JAM1,-56,1,NULL,(UBYTE *)"blue :",NULL};
  165.  
  166. struct StringInfo string1={(UBYTE *)name,NULL,0,30,0,0,0,0,0,0,NULL,0,NULL};
  167.  
  168. struct PropInfo prop1={AUTOKNOB|FREEHORIZ,0,0,0,0,0,0,0,0,0,0},
  169.                 prop2={AUTOKNOB|FREEHORIZ,0,0,0x0469,0,0,0,0,0,0,0},
  170.  
  171.                 prop3={AUTOKNOB|FREEHORIZ,0,0,0x1000,0,0,0,0,0,0,0},
  172.                 prop4={AUTOKNOB|FREEHORIZ,0,0,0x1000,0,0,0,0,0,0,0},
  173.                 prop5={AUTOKNOB|FREEHORIZ,0,0,0x1000,0,0,0,0,0,0,0};
  174.  
  175. struct Image image1,image2,image3,image4,image5;
  176.  
  177. struct Gadget gad1={NULL,585,12,PTT2,&text2,0,NULL,1,NULL},
  178.               gad2={&gad1,585,34,PTT2,&text3,0,NULL,2,NULL},
  179.               gad3={&gad2,585,56,PTT2,&text5,0,NULL,3,NULL},
  180.               gad4={&gad3,585,78,PTT2,&text7,0,NULL,4,NULL},
  181.               gad5={&gad4,585,100,PTT2,&text9,0,NULL,5,NULL},
  182.               gad6={&gad5,585,122,PTT2,&text11,0,NULL,6,NULL},
  183.               gad7={&gad6,585,144,PTT2,&text13,0,NULL,7,NULL},
  184.               gad8={&gad7,585,166,PTT2,&text15,0,NULL,8,NULL},
  185.  
  186.               gad9={NULL,138,135,PTT3,&text16,0,NULL,9,NULL},
  187.  
  188.               gad10={NULL,16,16,PTT2,&text18,0,NULL,10,NULL},
  189.               gad11={&gad10,70,16,PTT2,&text20,0,NULL,11,NULL},
  190.               gad12={&gad11,124,16,PTT2,&text22,0,NULL,12,NULL},
  191.               gad13={&gad12,178,16,PTT2,&text24,0,NULL,13,NULL},
  192.               gad14={&gad13,16,40,PTT2,&text26,0,NULL,14,NULL},
  193.               gad15={&gad14,70,40,PTT2,&text27,0,NULL,15,NULL},
  194.               gad16={&gad15,124,40,PTT2,&text28,0,NULL,16,NULL},
  195.               gad17={&gad16,16,62,PTT2,&text30,0,NULL,17,NULL},
  196.               gad18={&gad17,70,62,PTT2,&text31,0,NULL,18,NULL},
  197.               gad19={&gad18,124,62,PTT2,&text32,0,NULL,19,NULL},
  198.               gad20={&gad19,16,84,PTT2,&text34,0,NULL,20,NULL},
  199.               gad21={&gad20,70,84,PTT2,&text35,0,NULL,21,NULL},
  200.               gad22={&gad21,124,84,PTT2,&text36,0,NULL,22,NULL},
  201.               gad23={&gad22,16,106,PTT2,&text38,0,NULL,23,NULL},
  202.               gad24={&gad23,70,106,PTT2,&text39,0,NULL,24,NULL},
  203.               gad25={&gad24,124,106,PTT2,&text40,0,NULL,25,NULL},
  204.  
  205.               gad26={NULL,70,84,PTT2,&text42,0,NULL,26,NULL},
  206.               gad27={&gad26,124,84,PTT2,&text44,0,NULL,27,NULL},
  207.               gad28={&gad27,70,62,PTT2,&text46,0,NULL,28,NULL},
  208.               gad29={&gad28,124,62,PTT2,&text48,0,NULL,29,NULL},
  209.               gad30={&gad29,16,38,PTT2,&text51,0,NULL,30,NULL},
  210.  
  211.               gad31={&gad30,70,38,PTT2,&text53,0,NULL,31,NULL},
  212.               gad32={&gad31,124,38,PTT2,&text55,0,NULL,32,NULL},
  213.               gad33={&gad32,16,16,PTT2,&text57,0,NULL,33,NULL},
  214.               gad34={&gad33,70,16,PTT2,&text59,0,NULL,34,NULL},
  215.               gad35={&gad34,124,16,PTT2,&text61,0,NULL,35,NULL},
  216.               gad36={&gad35,178,16,PTT2,&text63,0,NULL,36,NULL},
  217.  
  218.               gad37={NULL,84,15,120,10,GADGHCOMP,RELVERIFY|STRINGCENTER,
  219.                   STRGADGET,(APTR)&bor3,NULL,NULL,0,(APTR)&string1,37,NULL},
  220.               gad38={&gad37,12,29,PTT3,&text16,0,NULL,38,NULL},
  221.               gad39={&gad38,120,29,PTT3,&text64,0,NULL,39,NULL},
  222.  
  223.               gad40={NULL,12,27,PTT3,&text64,0,NULL,40,NULL},
  224.               gad41={&gad40,120,27,PTT3,&text65,0,NULL,41,NULL},
  225.  
  226.               gad42={NULL,100,27,PTT3,&text16,0,NULL,42,NULL},
  227.  
  228.               gad43={NULL,24,15,PTT3,&text66,0,NULL,43,NULL},
  229.               gad44={&gad43,132,15,PTT3,&text67,0,NULL,44,NULL},
  230.               gad45={&gad44,12,39,200,10,GADGHCOMP,RELVERIFY,PROPGADGET,
  231.                   (APTR)&image1,NULL,&text68,0,(APTR)&prop1,45,NULL},
  232.               gad46={&gad45,12,61,200,10,GADGHCOMP,RELVERIFY,PROPGADGET,
  233.                   (APTR)&image2,NULL,&text69,0,(APTR)&prop2,46,NULL},
  234.               gad47={&gad46,24,77,PTT3,&text16,0,NULL,47,NULL},
  235.               gad48={&gad47,132,77,PTT3,&text64,0,NULL,48,NULL},
  236.  
  237.               gad49={NULL,15,17,PTT3,&text16,0,NULL,49,NULL},
  238.               gad50={&gad49,15,30,PTT3,&text64,0,NULL,50,NULL},
  239.               gad51={&gad50,15,43,PTT3,&text70,0,NULL,51,NULL},
  240.               gad52={&gad51,190,18,100,10,GADGHCOMP,RELVERIFY,PROPGADGET,
  241.                   (APTR)&image3,NULL,&text71,0,(APTR)&prop3,52,NULL},
  242.               gad53={&gad52,190,31,100,10,GADGHCOMP,RELVERIFY,PROPGADGET,
  243.                   (APTR)&image4,NULL,&text72,0,(APTR)&prop4,53,NULL},
  244.               gad54={&gad53,190,44,100,10,GADGHCOMP,RELVERIFY,PROPGADGET,
  245.                   (APTR)&image5,NULL,&text73,0,(APTR)&prop5,54,NULL};
  246.  
  247. struct NewScreen ns={
  248.     0,0,640,200,4,0,1,HIRES,CUSTOMSCREEN,&font,
  249.     (UBYTE *)"ImageEditor v2.4",NULL,NULL};
  250.  
  251. struct NewWindow nw1={
  252.     0,11,640,189,0,1,MOUSEBUTTONS|GADGETUP|CLOSEWINDOW|VANILLAKEY,
  253.     WINDOWCLOSE|SMART_REFRESH|ACTIVATE|RMBTRAP,&gad8,NULL,
  254.     (UBYTE *)"draw window",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  255.                  nw2={
  256.     0,129,174,71,0,1,0,SMART_REFRESH|BACKDROP,NULL,NULL,
  257.     (UBYTE *)"undo picture",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  258.                  nw3={
  259.     174,129,174,71,0,1,0,SMART_REFRESH|BACKDROP,NULL,NULL,
  260.     (UBYTE *)"origin picture",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  261.                  nw4={
  262.     137,29,376,153,0,1,GADGETUP,SMART_REFRESH|ACTIVATE,&gad9,NULL,
  263.     (UBYTE *)"info window",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  264.                  nw5={
  265.     0,11,166,58,0,1,0,SUPER_BITMAP|BORDERLESS|BACKDROP,NULL,NULL,
  266.     NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  267.                  nw6={
  268.     0,11,128+60+48,10,0,1,MOUSEBUTTONS|CLOSEWINDOW|VANILLAKEY,
  269.     WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH|ACTIVATE|RMBTRAP,
  270.     NULL,NULL,(UBYTE *)"ImageEditor v2.4",NULL,NULL,0,0,0,0,WBENCHSCREEN},
  271.                  nw7={
  272.     198,33,244,134,0,1,GADGETUP|CLOSEWINDOW|VANILLAKEY,
  273.     WINDOWDRAG|WINDOWCLOSE|SMART_REFRESH|ACTIVATE,&gad25,NULL,
  274.     (UBYTE *)"extras window",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  275.                  nw8={
  276.     0,127,176,73,0,1,CLOSEWINDOW,WINDOWDRAG|WINDOWCLOSE|SMART_REFRESH,
  277.     NULL,NULL,(UBYTE *)"show window",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  278.                  nw9={
  279.     0,11,498,9,0,1,0,SMART_REFRESH|BORDERLESS|BACKDROP,
  280.     NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  281.                  nw10={
  282.     0,11,18,174,0,1,0,SMART_REFRESH|BORDERLESS|BACKDROP,
  283.     NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  284.                  nw11={
  285.     198,44,244,112,0,1,GADGETUP|CLOSEWINDOW|VANILLAKEY,
  286.     WINDOWDRAG|WINDOWCLOSE|SMART_REFRESH|ACTIVATE,&gad36,NULL,
  287.     (UBYTE *)"disk window",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  288.                  nw12={
  289.     0,11,166,58,0,1,0,SUPER_BITMAP|BORDERLESS|BACKDROP,NULL,NULL,
  290.     NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  291.                  nw13={
  292.     204,76,232,47,0,1,GADGETUP,WINDOWDRAG|SMART_REFRESH|ACTIVATE,
  293.     &gad39,NULL,(UBYTE *)"edit name",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  294.                  nw14={
  295.     0,0,232,45,0,1,GADGETUP|VANILLAKEY,WINDOWDRAG|SMART_REFRESH|ACTIVATE,
  296.     &gad41,NULL,(UBYTE *)"last request",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  297.                  nw15={
  298.     170,77,300,45,0,1,GADGETUP,WINDOWDRAG|SMART_REFRESH|ACTIVATE,
  299.     &gad42,NULL,(UBYTE *)"aborting",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  300.                  nw16={
  301.     192,51,256,97,0,1,GADGETUP|CLOSEWINDOW|VANILLAKEY|INTUITICKS,
  302.     WINDOWDRAG|WINDOWCLOSE|SMART_REFRESH|ACTIVATE,&gad48,NULL,
  303.     (UBYTE *)"prefs window",NULL,NULL,0,0,0,0,CUSTOMSCREEN},
  304.                  nw17={
  305.     157,68,326,63,0,1,GADGETUP|CLOSEWINDOW|VANILLAKEY|INTUITICKS,
  306.     WINDOWDRAG|WINDOWCLOSE|SMART_REFRESH|ACTIVATE,&gad54,NULL,
  307.     (UBYTE *)"colors window",NULL,NULL,0,0,0,0,CUSTOMSCREEN};
  308.  
  309. main()
  310. {
  311.      /* init the lib-base-pointer by opening libs: */
  312.     if((GfxBase=(struct GfxBase *)
  313.         OpenLibrary("graphics.library",0L))==NULL)
  314.         ende();
  315.     if((IntuitionBase=(struct IntuitionBase *)
  316.         OpenLibrary("intuition.library",0L))==NULL)
  317.         ende();
  318.  
  319.      /* my-mouse-pointer-data in chip-mem: */
  320.     if((mouseptr=AllocMem(60L,MEMF_CHIP))==NULL) ende();
  321.     CopyMem(mousedata,mouseptr,60L);
  322.  
  323.      /* open the screen: */
  324.     if((scr=OpenScreen(&ns))==NULL) ende();
  325.     vp=&scr->ViewPort;
  326.  
  327.      /* init and set the user-palette: */
  328.     for(i=0;i<16;i++)
  329.         paletteu[i]=paletteb[i];
  330.     LoadRGB4(vp,paletteu,16L);
  331.  
  332.      /* open the main window: */
  333.     nw1.Screen=scr;
  334.     if((win1=OpenWindow(&nw1))==NULL) ende();
  335.     SetPointer(win1,mouseptr,13L,16L,-7L,-6L);
  336.     rp1=win1->RPort;
  337.     bline=rp1->TxBaseline;
  338.     SetAPen(rp1,1L);
  339.  
  340.      /* border the draw-area: */
  341.     rectangle(rp1,xmin-1,ymin-1,xmax+1,ymax+1);
  342.  
  343.      /* draw the color-gadgets: */
  344.     for(i=0;i<16;i++)
  345.         rectangle(rp1,531,11+i*11,555,20+i*11);
  346.     for(i=0;i<16;i++) {
  347.         SetAPen(rp1,(long)i);
  348.         RectFill(rp1,532L,(long)12+i*11,554L,(long)19+i*11);
  349.     }
  350.     SetAPen(rp1,1L);
  351.  
  352.      /* show the user the act colors: */
  353.     pfeil('l',1);
  354.     pfeil('r',0);
  355.  
  356.      /* open the undo-window: */
  357.     nw2.Screen=scr;
  358.     if((win2=OpenWindow(&nw2))==NULL) ende();
  359.     rp2=win2->RPort;
  360.  
  361.      /* open the origin-size-window: */
  362.     nw3.Screen=scr;
  363.     if((win3=OpenWindow(&nw3))==NULL) ende();
  364.     rp3=win3->RPort;
  365.  
  366.      /* take and execute commands: */
  367.     FOREVER {
  368.         if(anzeigen)
  369.             while(no_msg(win1) && no_msg(win8))
  370.                 sig=Wait(1L<<win1->UserPort->mp_SigBit |
  371.                      1L<<win8->UserPort->mp_SigBit);
  372.         else
  373.             while(no_msg(win1))
  374.                 WaitPort(win1->UserPort);
  375.  
  376.         class=msg->Class;
  377.         code=msg->Code;
  378.         gad=(struct Gadget *)msg->IAddress;
  379.         ReplyMsg(msg);
  380.  
  381.         if(anzeigen && sig==1L<<win8->UserPort->mp_SigBit) {
  382.             CloseWindow(win8);
  383.             win8=NULL;
  384.             anzeigen=0;
  385.         } else {
  386.             if(class==MOUSEBUTTONS)
  387.                 if(code==SELECTDOWN || code==MENUDOWN) {
  388.                     xpos=win1->MouseX;
  389.                     ypos=win1->MouseY;
  390.                     if(xpos>=xmin && xpos<=xmax && ypos>=ymin && ypos<=ymax)
  391.                         paint();
  392.                     else if(xpos>=531 && xpos<=555 && ypos>=11 && ypos<=185)
  393.                         if((ypos-11)%11!=10) {
  394.                             nr=(ypos-11)/11;
  395.                             buchst=code==SELECTDOWN?'l':'r';
  396.                             new_color(buchst,nr);
  397.                         }
  398.                 }
  399.             if(class==GADGETUP) {
  400.                 id=gad->GadgetID;
  401.                 switch(id) {
  402.                 case 1:
  403.                     if(!iconify()) alert();
  404.                     break;
  405.                 case 2:
  406.                     info();
  407.                     break;
  408.                 case 3:
  409.                     if(!flood()) alert();
  410.                     break;
  411.                 case 4:
  412.                     undo();
  413.                     break;
  414.                 case 5:
  415.                     if(!disk()) alert();
  416.                     break;
  417.                 case 6:
  418.                     if(!colors()) alert();
  419.                     break;
  420.                 case 7:
  421.                     if(!prefs()) alert();
  422.                     break;
  423.                 case 8:
  424.                     if(!extras()) alert();
  425.                     break;
  426.                 }
  427.             }
  428.             if(class==VANILLAKEY)
  429.                 switch(code) {
  430.                 case 'i':
  431.                     if(!iconify()) alert();
  432.                     break;
  433.                 case 'f':
  434.                     if(!flood()) alert();
  435.                     break;
  436.                 case 'u':
  437.                     undo();
  438.                     break;
  439.                 case 'd':
  440.                     if(!disk()) alert();
  441.                     break;
  442.                 case 'c':
  443.                     if(!colors()) alert();
  444.                     break;
  445.                 case 'p':
  446.                     if(!prefs()) alert();
  447.                     break;
  448.                 case 'e':
  449.                     if(!extras()) alert();
  450.                     break;
  451.                 case 'q':
  452.                     if(anzeigen) {
  453.                         CloseWindow(win8);
  454.                         win8=NULL;
  455.                         anzeigen=0;
  456.                     } else
  457.                         class=CLOSEWINDOW;
  458.                     break;
  459.                 }
  460.             if(class==CLOSEWINDOW)
  461.                 if(request())
  462.                     ende();
  463.         }
  464.     }
  465.  
  466. }
  467.  
  468. ende()
  469.  /* this function will close all basic windows, the screen, the libs and
  470.   * will also release the 60 bytes of chip-memory for my mouse pointer and
  471.   * then exit the program
  472.   */
  473. {
  474.     if(win8) CloseWindow(win8);
  475.     if(win3) CloseWindow(win3);
  476.     if(win2) CloseWindow(win2);
  477.     if(win1) CloseWindow(win1);
  478.     if(scr) CloseScreen(scr);
  479.  
  480.     if(mouseptr) FreeMem(mouseptr,60L);
  481.  
  482.     if(IntuitionBase) CloseLibrary(IntuitionBase);
  483.     if(GfxBase) CloseLibrary(GfxBase);
  484.  
  485.     exit(0);
  486. }
  487.  
  488. rectangle(rp,x1,y1,x2,y2)
  489.  /* this function is drawing a rectangle in the wished rastport at the
  490.   * wished position
  491.   */
  492.     struct RastPort *rp;
  493.     int x1,y1,x2,y2;
  494. {
  495.     Move(rp,(long)x1,(long)y1);
  496.     Draw(rp,(long)x2,(long)y1);
  497.     Draw(rp,(long)x2,(long)y2);
  498.     Draw(rp,(long)x1,(long)y2);
  499.     Draw(rp,(long)x1,(long)y1);
  500. }
  501.  
  502. pfeil(side,nr)
  503.  /* this function will mark the actual left/right color with a visible
  504.   * arrow; passed vars: char side is 'l' for left color or anything else
  505.   * (what about 'r'?) for the right color, int nr is the color number
  506.   */
  507.     char side;
  508.     int nr;
  509. {
  510.     long in,out;
  511.  
  512.     if(side=='l') {
  513.         in=529;
  514.         out=505;
  515.     } else {
  516.         in=557;
  517.         out=581;
  518.     }
  519.  
  520.     Move(rp1,out,(long)11+nr*11);
  521.     Draw(rp1,in,(long)16+nr*11);
  522.     Move(rp1,out,(long)11+nr*11);
  523.     Draw(rp1,out,(long)21+nr*11);
  524.     Draw(rp1,in,(long)16+nr*11);
  525. }
  526.  
  527. new_color(side,nr)
  528.  /* if the user changes a color, this function will be called with the
  529.   * side (char: 'l' for left or anything else for right) and the color
  530.   * number passed; one of the vars colorl/colorr will be set; this function
  531.   * will delete the old arrow and draw a new one
  532.   */
  533.     char side;
  534.     int nr;
  535. {
  536.     SetAPen(rp1,0L);
  537.     pfeil(side,side=='l'?colorl:colorr);
  538.  
  539.     if(side=='l')
  540.         colorl=nr;
  541.     else
  542.         colorr=nr;
  543.     SetAPen(rp1,1L);
  544.     pfeil(side,nr);
  545. }
  546.  
  547. paint()
  548.  /* this function will be called when the user pushed a mouse button in the
  549.   * draw-area; the actual position is set (in the main-function) in the vars
  550.   * xpos and ypos; this function will copy the actual picture in the undo-
  551.   * window, then select the draw color (dependind on which mouse button was
  552.   * pushed) and then draw the actual point; if now the user moves the mouse
  553.   * in the draw-area, this function will always draw a line from the last
  554.   * point it remember (last point drawn) to the actual position; if the user
  555.   * moves the pointer out of bounds, the function will start again with only
  556.   * one point (when the user starts drawing or gets out of bounds, the var
  557.   * xold (which remembers the last x-position) is set to an impossible value
  558.   * (1000) so the next time no line will be drawn); after every point or line
  559.   * this function takes a message from the draw-window-userport to see the
  560.   * new actual pointer position and to check if the user is still pressing
  561.   * the mouse button
  562.   */
  563. {
  564.     int xold,yold,xdiff,ydiff,xabs,yabs;
  565.  
  566.     update();
  567.  
  568.     buchst=code==SELECTDOWN?'l':'r';
  569.  
  570.     xold=1000;
  571.     do {
  572.         xnr=(xpos-5)/(3*aufl);
  573.         ynr=(ypos-12)/3;
  574.         if(xnr>=0 && xnr<breite && ynr>=0 && ynr<hoehe) {
  575.             if(xold!=1000) {
  576.                 xdiff=xnr-xold;
  577.                 ydiff=ynr-yold;
  578.                 xabs=ABS(xdiff);
  579.                 yabs=ABS(ydiff);
  580.                 if(xabs<=1 && yabs<=1)
  581.                     pixel(buchst,xnr,ynr);
  582.                 else
  583.                     if(xabs>=yabs) {
  584.                         if(xdiff>0)
  585.                             for(i=1;i<=xdiff;i++)
  586.                                 pixel(buchst,xold+i,yold+ydiff*i/xdiff);
  587.                         else
  588.                             for(i=-1;i>=xdiff;i--)
  589.                                 pixel(buchst,xold+i,yold+ydiff*i/xdiff);
  590.                     } else {
  591.                         if(ydiff>0)
  592.                             for(i=1;i<=ydiff;i++)
  593.                                 pixel(buchst,xold+xdiff*i/ydiff,yold+i);
  594.                         else
  595.                             for(i=-1;i>=ydiff;i--)
  596.                                 pixel(buchst,xold+xdiff*i/ydiff,yold+i);
  597.                     }
  598.  
  599.             }
  600.             else
  601.                 pixel(buchst,xnr,ynr);
  602.  
  603.             xold=xnr;
  604.             yold=ynr;
  605.         } else
  606.             xold=1000;
  607.  
  608.         msg=(struct IntuiMessage *)GetMsg(win1->UserPort);
  609.         if(msg) {
  610.             class=msg->Class;
  611.             code=msg->Code;
  612.             ReplyMsg(msg);
  613.         }
  614.  
  615.         xpos=win1->MouseX;
  616.         ypos=win1->MouseY;
  617.     } while(!(class==MOUSEBUTTONS && code==SELECTUP || code==MENUUP));
  618. }
  619.  
  620. pixel(buchst,x,y)
  621.  /* this function is used to draw; it sets the draw-colors in the needed
  622.   * rastports and then draw a rectangle in the draw-window, one or two points
  623.   * in the origin-size-window and maybe also one or two points in the show-
  624.   * window (two points are drawn when we are drawing in the lores-mode; the
  625.   * mode can be set in the pref(erence)s-part)
  626.   */
  627.     char buchst;
  628.     int x,y;
  629. {
  630.     long col;
  631.  
  632.     col=buchst=='l'?colorl:colorr;
  633.  
  634.     SetAPen(rp1,col);
  635.     RectFill(rp1,(long)5+x*3*aufl,(long)12+y*3,
  636.         (long)4+3*aufl+x*3*aufl,(long)14+y*3);
  637.  
  638.     SetAPen(rp3,col);
  639.     WritePixel(rp3,(long)4+x*aufl,(long)11+y);
  640.     if(aufl==2)
  641.         WritePixel(rp3,(long)5+x*aufl,(long)11+y);
  642.  
  643.     if(anzeigen) {
  644.         SetAPen(rp8,col);
  645.         WritePixel(rp8,(long)5+x*aufl,(long)12+y);
  646.         if(aufl==2)
  647.             WritePixel(rp8,(long)6+x*aufl,(long)12+y);
  648.     }
  649. }
  650.  
  651. text(rp,x,y,str)
  652.  /* this function is writing the wished text in the wished rastport at the
  653.   * wished position;
  654.   * remark: the var bline is initialized in the main-function after opening
  655.   *         the draw-window and it contains the number of lines the text
  656.   *         would be drawn higher than wished
  657.   */
  658.     struct RastPort *rp;
  659.     int x,y;
  660.     char *str;
  661. {
  662.     Move(rp,(long)x,(long)y+bline);
  663.     Text(rp,str,(long)strlen(str));
  664. }
  665.  
  666. update()
  667.  /* this function destroys the undo-picture by overwriting this with the
  668.   * origin-picture; it is called e.g. when the user draws the next point
  669.   */
  670. {
  671.     ClipBlit(rp3,4L,11L,rp2,4L,11L,breite*aufl,hoehe,(long)0xc0);
  672. }
  673.  
  674. undo()
  675.  /* this function will undo the last user-action by bringing the last
  676.   * 'saved' picture on the draw-window
  677.   */
  678. {
  679.     reverse(win1,4);
  680.  
  681.     ClipBlit(rp2,4L,11L,rp3,4L,11L,breite*aufl,hoehe,(long)0xc0);
  682.     if(anzeigen)
  683.         ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  684.     erase();
  685.     get_msgs();
  686.  
  687.     reverse(win1,4);
  688. }
  689.  
  690. erase()
  691.  /* because the undo-window is smaller than the draw-window (to save chip-
  692.   * memory) after every undo (or after iconifying, when the picture is also
  693.   * remembered in small-size) we must erase the picture, what this function
  694.   * is doing (first of all the small-picture is copied in the draw-area in
  695.   * the upper left corner and than this function is called)
  696.   */
  697. {
  698.     for(i=breite*aufl-1;i>=0;i--) {
  699.         ClipBlit(rp3,(long)4+i,11L,rp1,(long)5+i*3,12L,
  700.             1L,hoehe,(long)0xc0);
  701.         ClipBlit(rp1,(long)5+i*3,12L,rp1,(long)6+i*3,12L,
  702.             1L,hoehe,(long)0xc0);
  703.         ClipBlit(rp1,(long)5+i*3,12L,rp1,(long)7+i*3,12L,
  704.             1L,hoehe,(long)0xc0);
  705.     }
  706.     for(i=hoehe-1;i>=0;i--) {
  707.         ClipBlit(rp1,5L,(long)12+i,rp1,5L,(long)12+i*3,
  708.             breite*3*aufl,1L,(long)0xc0);
  709.         ClipBlit(rp1,5L,(long)12+i*3,rp1,5L,(long)13+i*3,
  710.             breite*3*aufl,1L,(long)0xc0);
  711.         ClipBlit(rp1,5L,(long)12+i*3,rp1,5L,(long)14+i*3,
  712.             breite*3*aufl,1L,(long)0xc0);
  713.     }
  714. }
  715.  
  716. info()
  717.  /* this function is opening a window and displaying some informations to
  718.   * this program
  719.   */
  720. {
  721.     reverse(win1,2);
  722.  
  723.     nw4.Screen=scr;
  724.     if((win4=OpenWindow(&nw4))==NULL)
  725.         alert();
  726.     else {
  727.         SetPointer(win4,mouseptr,13L,16L,-7L,-6L);
  728.         rp4=win4->RPort;
  729.  
  730.         SetAPen(rp4,2L);
  731.         text(rp4,124,15,"ImageEditor v2.4");
  732.         SetAPen(rp4,1L);
  733.         text(rp4,88,27,"© 1990 by Robert Junghans");
  734.         text(rp4,84,39,"date of release: 20.Apr.90");
  735.         SetAPen(rp4,2L);
  736.         text(rp4,12,51,"Tool");
  737.         SetAPen(rp4,1L);
  738.         text(rp4,52,51,"for programmers interested in graphics.");
  739.         text(rp4,84,59,"This program is");
  740.         SetAPen(rp4,2L);
  741.         text(rp4,212,59,"Shareware.");
  742.         SetAPen(rp4,1L);
  743.         text(rp4,52,67,"If you use it please send $5.00 to");
  744.         text(rp4,128,75,"Robert Junghans");
  745.         text(rp4,112,83,"Agnes Straub Weg 10");
  746.         text(rp4,132,91,"1000 Berlin 47");
  747.         text(rp4,140,99,"West Germany");
  748.         text(rp4,60,111,"Improvement suggestions welcome.");
  749.         text(rp4,64,123,"[ see");
  750.         SetAPen(rp4,2L);
  751.         text(rp4,112,123,"im24.doc");
  752.         SetAPen(rp4,1L);
  753.         text(rp4,184,123,"for more infos ]");
  754.  
  755.         WaitPort(win4->UserPort);
  756.         CloseWindow(win4);
  757.  
  758.         get_msgs();
  759.     }
  760.     reverse(win1,2);
  761. }
  762.  
  763. get_msgs()
  764.  /* if a time-intensive function was called (e.g. undo or disk etc.) so the
  765.   * user could activate some draw-window-gadgets in the time the function
  766.   * was executed; to not let him wait until all 'clicked' functions will be
  767.   * also executed, this function is called and it is 'clearing' the user-
  768.   * ports of the draw-window and maybe of the show-window of all messages
  769.   */
  770. {
  771.     message(win1);
  772.     if(anzeigen) message(win8);
  773. }
  774.  
  775. message(win)
  776.  /* this function will 'take' all messages send to the wished window and
  777.   * reply them
  778.   */
  779.     struct Window *win;
  780. {
  781.     while(msg=(struct IntuiMessage *)GetMsg(win->UserPort))
  782.         ReplyMsg(msg);
  783. }
  784.  
  785. alert()
  786.  /* this simple function displays an alert looking a little bit like
  787.   * the well known meditation from india; the best way to continue is
  788.   * to push the left mouse button; this function will be called when an
  789.   * other function can't get the memory it needs and must be aborted
  790.   */
  791. {
  792.     static BYTE alert[]={
  793.         0,248,15,"Not enough memory!",1,
  794.         0,176,28,"The actual function will be aborted!",1,
  795.         0,128,41,"Please press the left mouse button to continue..",0};
  796.  
  797.     DisplayAlert(RECOVERY_ALERT,alert,53L);
  798. }
  799.  
  800. reverse(win,id)
  801.  /* this function will search in the wished window-gadget-list for the
  802.   * gadget with the wished id and then reverse it; if a gadget with the
  803.   * given id does not exist in the list of the wished window, no gadget
  804.   * will be inverted
  805.   */
  806.     struct Window *win;
  807.     int id;
  808. {
  809.     struct RastPort *rp;
  810.     struct Gadget *gad;
  811.     int done;
  812.  
  813.     rp=win->RPort;
  814.     gad=win->FirstGadget;
  815.     done=0;
  816.  
  817.     if(gad)
  818.         do {
  819.             if(gad->GadgetID==id) {
  820.                 SetDrMd(rp,JAM1|COMPLEMENT);
  821.                 RectFill(rp,(long)gad->LeftEdge,(long)gad->TopEdge,
  822.                     (long)gad->LeftEdge+gad->Width-1,
  823.                     (long)gad->TopEdge+gad->Height-1);
  824.                 SetDrMd(rp,JAM1);
  825.                 done=1;
  826.             }
  827.             gad=gad->NextGadget;
  828.         } while(gad && !done);
  829. }
  830.  
  831. iconify()
  832.  /* if the user needs the chip-memory which is used by im24 he must not quit
  833.   * the program; he can also iconify it, i.e. the windows and the screen from
  834.   * im24 will be closed and im24 will open a small window on the workbench
  835.   * screen and the user can run another programs which need chip-memory;
  836.   * after this the user just have to activate the im24-window and push the
  837.   * right mouse button and im24 will open screen and windows and display the
  838.   * old picture so the user can work with im24 again;
  839.   * remark: by iconifying you will lose the undo-picture!
  840.   * remark: the iconified-wb-window has also a closewindow-gadget, so you
  841.   *         can also quit im24 when it is iconified
  842.   * remark: the anzeigen-flag will be cleared even if it was set
  843.   */
  844. {
  845.     struct BitMap bmap;
  846.  
  847.     end=0;
  848.     reverse(win1,1);
  849.  
  850.     InitBitMap(&bmap,4L,breite*aufl,hoehe);
  851.     for(i=0;i<4;i++)
  852.         if((bmap.Planes[i]=AllocRaster(breite*aufl,hoehe))==NULL) {
  853.             for(j=0;j<i;j++)
  854.                 FreeRaster(bmap.Planes[j],breite*aufl,hoehe);
  855.             reverse(win1,1);
  856.             return(0);
  857.         }
  858.  
  859.     nw5.Width=breite*aufl;
  860.     nw5.Height=hoehe;
  861.     nw5.Screen=scr;
  862.     nw5.BitMap=&bmap;
  863.     if((win5=OpenWindow(&nw5))==NULL) {
  864.         for(i=0;i<4;i++)
  865.             if(bmap.Planes[i])
  866.                 FreeRaster(bmap.Planes[i],breite*aufl,hoehe);
  867.         reverse(win1,1);
  868.         return(0);
  869.     }
  870.     rp5=win5->RPort;
  871.  
  872.     ClipBlit(rp3,4L,11L,rp5,0L,0L,breite*aufl,hoehe,(long)0xc0);
  873.  
  874.     if((win6=OpenWindow(&nw6))==NULL) {
  875.         CloseWindow(win5);
  876.  
  877.         for(i=0;i<4;i++)
  878.             if(bmap.Planes[i])
  879.                 FreeRaster(bmap.Planes[i],breite*aufl,hoehe);
  880.         reverse(win1,1);
  881.         return(0);
  882.     }
  883.     SetPointer(win6,mouseptr,13L,16L,-7L,-6L);
  884.  
  885.     close_all();
  886.  
  887.     do {
  888.         while(no_msg(win6))
  889.             WaitPort(win6->UserPort);
  890.  
  891.         class=msg->Class;
  892.         code=msg->Code;
  893.         ReplyMsg(msg);
  894.  
  895.         if(class==VANILLAKEY)
  896.             if(code=='q')
  897.                 class=CLOSEWINDOW;
  898.         if(class==CLOSEWINDOW)
  899.             if(request()) {
  900.                 for(i=0;i<4;i++)
  901.                     FreeRaster(bmap.Planes[i],breite*aufl,hoehe);
  902.                 CloseWindow(win6);
  903.  
  904.                 ende();
  905.             }
  906.         if(class==MOUSEBUTTONS)
  907.             if(code==MENUDOWN) {
  908.  
  909.                 if((scr=OpenScreen(&ns))==NULL) {
  910.                     alert();
  911.                     continue;
  912.                 }
  913.                 vp=&scr->ViewPort;
  914.  
  915.                 LoadRGB4(vp,paletteu,16L);
  916.  
  917.                 nw1.Screen=scr;
  918.                 if((win1=OpenWindow(&nw1))==NULL) {
  919.                     close_all();
  920.                     alert();
  921.                     continue;
  922.                 }
  923.                 SetPointer(win1,mouseptr,13L,16L,-7L,-6L);
  924.                 reverse(win1,1);
  925.                 rp1=win1->RPort;
  926.                 SetAPen(rp1,1L);
  927.  
  928.                 rectangle(rp1,xmin-1,ymin-1,xmax+1,ymax+1);
  929.  
  930.                 for(i=0;i<16;i++)
  931.                     rectangle(rp1,531,11+i*11,555,20+i*11);
  932.                 for(i=0;i<16;i++) {
  933.                     SetAPen(rp1,(long)i);
  934.                     RectFill(rp1,532L,(long)12+i*11,554L,(long)19+i*11);
  935.                 }
  936.                 SetAPen(rp1,1L);
  937.  
  938.                 pfeil('l',colorl);
  939.                 pfeil('r',colorr);
  940.  
  941.                 nw2.Screen=scr;
  942.                 if((win2=OpenWindow(&nw2))==NULL) {
  943.                     close_all();
  944.                     alert();
  945.                     continue;
  946.                 }
  947.                 rp2=win2->RPort;
  948.  
  949.                 nw3.Screen=scr;
  950.                 if((win3=OpenWindow(&nw3))==NULL) {
  951.                     close_all();
  952.                     alert();
  953.                     continue;
  954.                 }
  955.                 rp3=win3->RPort;
  956.  
  957.                 BltBitMapRastPort(&bmap,0L,0L,rp3,4L,11L,
  958.                     breite*aufl,hoehe,(long)0xc0);
  959.  
  960.                 for(i=0;i<4;i++)
  961.                     FreeRaster(bmap.Planes[i],breite*aufl,hoehe);
  962.                 CloseWindow(win6);
  963.  
  964.                 anzeigen=0;
  965.  
  966.                 update();
  967.                 erase();
  968.  
  969.                 get_msgs();
  970.                 end=1;
  971.             }
  972.     } while(!end);
  973.  
  974.     reverse(win1,1);
  975.     return(1);
  976. }
  977.  
  978. close_all()
  979.  /* this function is closing the screen-windows and the screen to get
  980.   * as much chip-memory as possible free; it also sets the window- and
  981.   * screen-pointer to null, because this pointer are also flags if the
  982.   * windows and the screen are open (to avoid closing them twice)
  983.   */
  984. {
  985.     if(win8) CloseWindow(win8);
  986.     if(win5) CloseWindow(win5);
  987.     if(win3) CloseWindow(win3);
  988.     if(win2) CloseWindow(win2);
  989.     if(win1) CloseWindow(win1);
  990.     if(scr) CloseScreen(scr);
  991.  
  992.     win8=win5=win3=win2=win1=scr=NULL;
  993. }
  994.  
  995. request()
  996.  /* this function will ask the user if he wants to quit the program;
  997.   * it returns 1 if he wants to quit, 0 if not
  998.   */
  999. {
  1000.     int response;
  1001.  
  1002.     if(scr) {
  1003.         nw14.Screen=scr;
  1004.         nw14.Type=CUSTOMSCREEN;
  1005.     } else
  1006.         nw14.Type=WBENCHSCREEN;
  1007.  
  1008.     if((win14=OpenWindow(&nw14))==NULL)
  1009.         return(0);
  1010.     SetPointer(win14,mouseptr,13L,16L,-7L,-6L);
  1011.     rp14=win14->RPort;
  1012.     SetAPen(rp14,1L);
  1013.  
  1014.     text(rp14,32,15,"really quit the prg.?");
  1015.  
  1016.     while(no_msg(win14))
  1017.         WaitPort(win14->UserPort);
  1018.  
  1019.     class=msg->Class;
  1020.     code=msg->Code;
  1021.     gad=(struct Gadget *)msg->IAddress;
  1022.     ReplyMsg(msg);
  1023.  
  1024.     if(class==GADGETUP)
  1025.         response=gad->GadgetID==41;
  1026.     if(class==VANILLAKEY)
  1027.         response=code=='o';
  1028.  
  1029.     CloseWindow(win14);
  1030.     return(response);
  1031. }
  1032.  
  1033. flood()
  1034.  /* this function will flood a area using the graphics.library-function;
  1035.   * first of all the function is waiting for a message, it is handling only
  1036.   * three messages: the pressing of the flood-gadget or the pressing of the
  1037.   * f-key to end the function immediately (e.g. when the user choose this
  1038.   * function and now doesn't want to flood anything) or the pushing of a
  1039.   * mouse button in the draw-area, then a temporary raster will be allocated
  1040.   * (important for the graphics.library-function) and initialized; then the
  1041.   * origin-size-picture will be copied in the undo-window and the draw color
  1042.   * will be choosed; then our temporary raster will be assigned to the ori-
  1043.   * gin-size-window and we will border the picture-area with an color diffe-
  1044.   * rent from the color under the mouse pointer (so we won't flood the whole
  1045.   * window) and then the graphics.library-function will be called; after this
  1046.   * the same (assignment and flooding) will happen to the draw-window; then
  1047.   * the raster-memory will be given back to the system and last the picture
  1048.   * will be copied to the show-window (when this exists)
  1049.   */
  1050. {
  1051.     long col,col2;
  1052.     struct TmpRas tras;
  1053.     APTR buffer=NULL;
  1054.     int brei,hoe;
  1055.  
  1056.     end=0;
  1057.     reverse(win1,3);
  1058.  
  1059.     do {
  1060.         while(no_msg(win1))
  1061.             WaitPort(win1->UserPort);
  1062.  
  1063.         class=msg->Class;
  1064.         code=msg->Code;
  1065.         gad=(struct Gadget *)msg->IAddress;
  1066.         ReplyMsg(msg);
  1067.  
  1068.         if(class==MOUSEBUTTONS)
  1069.             if(code==SELECTDOWN || code==MENUDOWN) {
  1070.                 xpos=win1->MouseX;
  1071.                 ypos=win1->MouseY;
  1072.                 if(xpos>=xmin && xpos<=xmax && ypos>=ymin && ypos<=ymax) {
  1073.  
  1074.                     if((buffer=AllocRaster(640L,200L))==NULL) {
  1075.                         reverse(win1,3);
  1076.                         return(0);
  1077.                     }
  1078.                     InitTmpRas(&tras,buffer,(long)RASSIZE(640,200));
  1079.  
  1080.                     update();
  1081.  
  1082.                     xnr=(xpos-5)/(3*aufl);
  1083.                     ynr=(ypos-12)/3;
  1084.  
  1085.                     col=code==SELECTDOWN?colorl:colorr;
  1086.                     col2=ReadPixel(rp1,(long)xpos,(long)ypos)+1;
  1087.  
  1088.                     rp3->TmpRas=&tras;
  1089.                     SetAPen(rp3,col2);
  1090.                     brei=breite;
  1091.                     hoe=hoehe;
  1092.                     rectangle(rp3,3,10,4+brei*aufl,11+hoe);
  1093.  
  1094.                     SetAPen(rp3,col);
  1095.                     Flood(rp3,1L,(long)xnr*aufl+4,(long)ynr+11);
  1096.                     rp3->TmpRas=NULL;
  1097.  
  1098.                     rp1->TmpRas=&tras;
  1099.                     SetAPen(rp1,col2);
  1100.                     rectangle(rp1,xmin-1,ymin-1,xmax+1,ymax+1);
  1101.                     SetAPen(rp1,col);
  1102.                     Flood(rp1,1L,(long)xpos,(long)ypos);
  1103.                     SetAPen(rp1,1L);
  1104.                     rectangle(rp1,xmin-1,ymin-1,xmax+1,ymax+1);
  1105.                     rp1->TmpRas=NULL;
  1106.  
  1107.                     FreeRaster(buffer,640L,200L);
  1108.  
  1109.                     if(anzeigen)
  1110.                         ClipBlit(rp3,4L,11L,rp8,5L,12L,
  1111.                             breite*aufl,hoehe,(long)0xc0);
  1112.  
  1113.                     get_msgs();
  1114.  
  1115.                     end=1;
  1116.                 }
  1117.             }
  1118.         if(class==GADGETUP)
  1119.             end=gad->GadgetID==3;
  1120.         if(class==VANILLAKEY)
  1121.             if(code=='f') {
  1122.                 class=0;
  1123.                 end=1;
  1124.             }
  1125.  
  1126.     } while(!end);
  1127.  
  1128.     reverse(win1,3);
  1129.     return(1);
  1130. }
  1131.  
  1132. extras()
  1133.  /* in the here opened extras-window the user can open the show-window,
  1134.   * clear the draw-area or flip and move the picture
  1135.   */
  1136. {
  1137.     reverse(win1,8);
  1138.     gad11.NextGadget=anzeigen?NULL:&gad10;
  1139.  
  1140.     nw7.Screen=scr;
  1141.     if((win7=OpenWindow(&nw7))==NULL)
  1142.         return(0);
  1143.     SetPointer(win7,mouseptr,13L,16L,-7L,-6L);
  1144.     rp7=win7->RPort;
  1145.     SetAPen(rp7,1L);
  1146.     rectangle(rp7,12,37,177,127);
  1147.  
  1148.     do {
  1149.         while(no_msg(win7))
  1150.             WaitPort(win7->UserPort);
  1151.  
  1152.         class=msg->Class;
  1153.         code=msg->Code;
  1154.         gad=(struct Gadget *)msg->IAddress;
  1155.         ReplyMsg(msg);
  1156.  
  1157.         if(class==GADGETUP) {
  1158.             id=gad->GadgetID;
  1159.             switch(id) {
  1160.             case 10:
  1161.                 if(!show()) alert();
  1162.                 break;
  1163.             case 11:
  1164.                 clear();
  1165.                 break;
  1166.             case 12:
  1167.                 if(!mirror()) alert();
  1168.                 break;
  1169.             case 13:
  1170.                 if(!upside()) alert();
  1171.                 break;
  1172.             case 14:
  1173.             case 15:
  1174.             case 16:
  1175.                 updown(id-13);
  1176.                 break;
  1177.             case 17:
  1178.             case 18:
  1179.             case 19:
  1180.                 updown(16-id);
  1181.                 break;
  1182.             case 20:
  1183.             case 21:
  1184.             case 22:
  1185.                 rightleft(id-19);
  1186.                 break;
  1187.             case 23:
  1188.             case 24:
  1189.             case 25:
  1190.                 rightleft(22-id);
  1191.                 break;
  1192.             }
  1193.         }
  1194.         if(class==VANILLAKEY)
  1195.             switch(code) {
  1196.             case 's':
  1197.                 if(!show()) alert();
  1198.                 break;
  1199.             case 'c':
  1200.                 clear();
  1201.                 break;
  1202.             case 'h':
  1203.                 if(!mirror()) alert();
  1204.                 break;
  1205.             case 'v':
  1206.                 if(!upside()) alert();
  1207.                 break;
  1208.             case 'u':
  1209.                 updown(1);
  1210.                 break;
  1211.             case 'd':
  1212.                 updown(-1);
  1213.                 break;
  1214.             case 'r':
  1215.                 rightleft(1);
  1216.                 break;
  1217.             case 'l':
  1218.                 rightleft(-1);
  1219.                 break;
  1220.             case 'q':
  1221.                 class=CLOSEWINDOW;
  1222.                 break;
  1223.             }
  1224.     } while(class!=CLOSEWINDOW);
  1225.  
  1226.     class=0;
  1227.     CloseWindow(win7);
  1228.     reverse(win1,8);
  1229.     get_msgs();
  1230.     return(1);
  1231. }
  1232.  
  1233. show()
  1234.  /* this function will open the show-window, copy the picture from the
  1235.   * origin-size-window and hide the show-gadget in the extras-window;
  1236.   * the anzeigen-flag will be set
  1237.   */
  1238. {
  1239.     int brei,hoe;
  1240.  
  1241.     nw8.Screen=scr;
  1242.     if((win8=OpenWindow(&nw8))==NULL)
  1243.         return(0);
  1244.     SetPointer(win8,mouseptr,13L,16L,-7L,-6L);
  1245.     rp8=win8->RPort;
  1246.     SetAPen(rp8,1L);
  1247.     brei=breite;
  1248.     hoe=hoehe;
  1249.     rectangle(rp8,4,11,5+brei*aufl,12+hoe);
  1250.     ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1251.     anzeigen=1;
  1252.  
  1253.     gad11.NextGadget=NULL;
  1254.     SetAPen(rp7,0L);
  1255.     RectFill(rp7,15L,15L,66L,35L);
  1256.  
  1257.     return(1);
  1258. }
  1259.  
  1260. clear()
  1261.  /* this function is copying the actual picture in the undo-window,
  1262.   * then the whole drawing area is filled with the 'left color'; the
  1263.   * origin-size-window and the show-window are filled too
  1264.   */
  1265. {
  1266.     update();
  1267.  
  1268.     SetAPen(rp1,(long)colorl);
  1269.     RectFill(rp1,(long)xmin,(long)ymin,(long)xmax,(long)ymax);
  1270.  
  1271.     SetAPen(rp3,(long)colorl);
  1272.     RectFill(rp3,4L,11L,3+breite*aufl,10+hoehe);
  1273.  
  1274.     if(anzeigen) {
  1275.         SetAPen(rp8,(long)colorl);
  1276.         RectFill(rp8,5L,12L,(long)4+breite*aufl,(long)11+hoehe);
  1277.     }
  1278. }
  1279.  
  1280. mirror()
  1281.  /* this function is flipping (horizonthal) the whole picture;
  1282.   * remark: the undo-picture gets lost
  1283.   */
  1284. {
  1285.     reverse(win7,12);
  1286.  
  1287.     nw10.Screen=scr;
  1288.     if((win10=OpenWindow(&nw10))==NULL)
  1289.         alert();
  1290.     else {
  1291.         rp10=win10->RPort;
  1292.  
  1293.         for(i=0;i<breite/2;i++) {
  1294.             ClipBlit(rp1,(long)5+i*3*aufl,12L,rp10,0L,0L,
  1295.                 (long)3*aufl,hoehe*3,(long)0xc0);
  1296.             ClipBlit(rp1,(long)5+(breite-i-1)*3*aufl,12L,rp1,
  1297.                 (long)5+i*3*aufl,12L,(long)3*aufl,hoehe*3,(long)0xc0);
  1298.             ClipBlit(rp10,0L,0L,rp1,(long)5+(breite-i-1)*3*aufl,12L,
  1299.                 (long)3*aufl,hoehe*3,(long)0xc0);
  1300.  
  1301.             ClipBlit(rp3,(long)4+i*aufl,11L,rp10,0L,0L,
  1302.                 (long)aufl,hoehe,(long)0xc0);
  1303.             ClipBlit(rp3,(long)4+(breite-i-1)*aufl,11L,rp3,
  1304.                 (long)4+i*aufl,11L,(long)aufl,hoehe,(long)0xc0);
  1305.             ClipBlit(rp10,0L,0L,rp3,(long)4+(breite-i-1)*aufl,11L,
  1306.                 (long)aufl,hoehe,(long)0xc0);
  1307.         }
  1308.  
  1309.         if(anzeigen)
  1310.             ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1311.         update();
  1312.  
  1313.         message(win7);
  1314.  
  1315.         CloseWindow(win10);
  1316.     }
  1317.  
  1318.     reverse(win7,12);
  1319.     return(1);
  1320. }
  1321.  
  1322. upside()
  1323.  /* this function is flipping (vertikal) the whole picture;
  1324.   * remark: the undo-picture gets lost
  1325.   */
  1326. {
  1327.     reverse(win7,13);
  1328.  
  1329.     nw9.Screen=scr;
  1330.     if((win9=OpenWindow(&nw9))==NULL)
  1331.         alert();
  1332.     else {
  1333.         rp9=win9->RPort;
  1334.  
  1335.         for(i=0;i<hoehe/2;i++) {
  1336.             ClipBlit(rp1,5L,(long)12+i*3,rp9,0L,0L,
  1337.                 breite*3*aufl,3L,(long)0xc0);
  1338.             ClipBlit(rp1,5L,(long)9+(hoehe-i)*3,rp1,
  1339.                 5L,(long)12+i*3,breite*3*aufl,3L,(long)0xc0);
  1340.             ClipBlit(rp9,0L,0L,rp1,5L,(long)9+(hoehe-i)*3,
  1341.                 breite*3*aufl,3L,(long)0xc0);
  1342.  
  1343.             ClipBlit(rp3,4L,(long)11+i,rp9,0L,0L,
  1344.                 breite*aufl,1L,(long)0xc0);
  1345.             ClipBlit(rp3,4L,(long)10+hoehe-i,rp3,
  1346.                 4L,(long)11+i,breite*aufl,1L,(long)0xc0);
  1347.             ClipBlit(rp9,0L,0L,rp3,4L,(long)10+hoehe-i,
  1348.                 breite*aufl,1L,(long)0xc0);
  1349.         }
  1350.  
  1351.         if(anzeigen)
  1352.             ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1353.         update();
  1354.  
  1355.         message(win7);
  1356.  
  1357.         CloseWindow(win9);
  1358.     }
  1359.  
  1360.     update();
  1361.  
  1362.     reverse(win7,13);
  1363.     return(1);
  1364. }
  1365.  
  1366. updown(zahl)
  1367.  /* this function moves the whole picture the wished number of pixels up;
  1368.   * remark: the undo-picture gets lost
  1369.   */
  1370.     int zahl;
  1371. {
  1372.     if(zahl>0)
  1373.         reverse(win7,13+zahl);
  1374.     else
  1375.         reverse(win7,16-zahl);
  1376.  
  1377.     nw9.Screen=scr;
  1378.     if((win9=OpenWindow(&nw9))==NULL)
  1379.         alert();
  1380.     else {
  1381.         rp9=win9->RPort;
  1382.  
  1383.         if(zahl>0) {
  1384.  
  1385.             ClipBlit(rp3,4L,11L,rp9,0L,0L,
  1386.                 breite*aufl,(long)zahl,(long)0xc0);
  1387.             ClipBlit(rp3,4L,(long)11+zahl,rp3,
  1388.                 4L,11L,breite*aufl,(long)hoehe-zahl,(long)0xc0);
  1389.             ClipBlit(rp9,0L,0L,rp3,4L,(long)11+hoehe-zahl,
  1390.                 breite*aufl,(long)zahl,(long)0xc0);
  1391.  
  1392.             if(anzeigen)
  1393.                 ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1394.  
  1395.             ClipBlit(rp1,5L,12L,rp9,0L,0L,
  1396.                 breite*3*aufl,(long)zahl*3,(long)0xc0);
  1397.             ClipBlit(rp1,5L,(long)12+zahl*3,rp1,
  1398.                 5L,12L,breite*3*aufl,(long)(hoehe-zahl)*3,(long)0xc0);
  1399.             ClipBlit(rp9,0L,0L,rp1,5L,(long)12+(hoehe-zahl)*3,
  1400.                 breite*3*aufl,(long)zahl*3,(long)0xc0);
  1401.  
  1402.         } else {
  1403.  
  1404.             ClipBlit(rp3,4L,(long)11+hoehe+zahl,rp9,0L,0L,
  1405.                 breite*aufl,(long)-zahl,(long)0xc0);
  1406.             ClipBlit(rp3,4L,11L,rp3,4L,(long)11-zahl,
  1407.                 breite*aufl,(long)hoehe+zahl,(long)0xc0);
  1408.             ClipBlit(rp9,0L,0L,rp3,4L,11L,
  1409.                 breite*aufl,(long)-zahl,(long)0xc0);
  1410.  
  1411.             if(anzeigen)
  1412.                 ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1413.  
  1414.             ClipBlit(rp1,5L,(long)12+(hoehe+zahl)*3,rp9,0L,0L,
  1415.                 breite*3*aufl,(long)-zahl*3,(long)0xc0);
  1416.             ClipBlit(rp1,5L,12L,rp1,5L,(long)12-zahl*3,
  1417.                 breite*3*aufl,(long)(hoehe+zahl)*3,(long)0xc0);
  1418.             ClipBlit(rp9,0L,0L,rp1,5L,12L,
  1419.                 breite*3*aufl,(long)-zahl*3,(long)0xc0);
  1420.  
  1421.         }
  1422.  
  1423.         update();
  1424.  
  1425.         CloseWindow(win9);
  1426.     }
  1427.  
  1428.     if(zahl>0)
  1429.         reverse(win7,13+zahl);
  1430.     else
  1431.         reverse(win7,16-zahl);
  1432. }
  1433.  
  1434. rightleft(zahl)
  1435.  /* this function moves the whole picture the wished number of pixels right;
  1436.   * remark: the undo-picture gets lost
  1437.   */
  1438.     int zahl;
  1439. {
  1440.     if(zahl>0)
  1441.         reverse(win7,19+zahl);
  1442.     else
  1443.         reverse(win7,22-zahl);
  1444.  
  1445.     nw10.Screen=scr;
  1446.     if((win10=OpenWindow(&nw10))==NULL)
  1447.         alert();
  1448.     else {
  1449.         rp10=win10->RPort;
  1450.  
  1451.         if(zahl>0) {
  1452.  
  1453.             ClipBlit(rp3,(long)4+(breite-zahl)*aufl,11L,rp10,0L,0L,
  1454.                 (long)zahl*aufl,hoehe,(long)0xc0);
  1455.             ClipBlit(rp3,4L,11L,rp3,(long)4+(zahl*aufl),11L,
  1456.                 (long)(breite-zahl)*aufl,hoehe,(long)0xc0);
  1457.             ClipBlit(rp10,0L,0L,rp3,4L,11L,
  1458.                 (long)zahl*aufl,hoehe,(long)0xc0);
  1459.  
  1460.             if(anzeigen)
  1461.                 ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1462.  
  1463.             ClipBlit(rp1,(long)5+(breite-zahl)*3*aufl,12L,rp10,0L,0L,
  1464.                 (long)zahl*3*aufl,hoehe*3,(long)0xc0);
  1465.             ClipBlit(rp1,5L,12L,rp1,(long)5+zahl*3*aufl,12L,
  1466.                 (long)(breite-zahl)*3*aufl,hoehe*3,(long)0xc0);
  1467.             ClipBlit(rp10,0L,0L,rp1,5L,12L,
  1468.                 (long)zahl*3*aufl,hoehe*3,(long)0xc0);
  1469.  
  1470.         } else {
  1471.  
  1472.             ClipBlit(rp3,4L,11L,rp10,0L,0L,
  1473.                 (long)-zahl*aufl,hoehe,(long)0xc0);
  1474.             ClipBlit(rp3,(long)4-zahl*aufl,11L,rp3,4L,11L,
  1475.                 (long)(breite+zahl)*aufl,hoehe,(long)0xc0);
  1476.             ClipBlit(rp10,0L,0L,rp3,(long)4+(breite+zahl)*aufl,11L,
  1477.                 (long)-zahl*aufl,hoehe,(long)0xc0);
  1478.  
  1479.             if(anzeigen)
  1480.                 ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1481.  
  1482.             ClipBlit(rp1,5L,12L,rp10,0L,0L,
  1483.                 (long)-zahl*3*aufl,hoehe*3,(long)0xc0);
  1484.             ClipBlit(rp1,(long)5-zahl*3*aufl,12L,rp1,5L,12L,
  1485.                 (long)(breite+zahl)*3*aufl,hoehe*3,(long)0xc0);
  1486.             ClipBlit(rp10,0L,0L,rp1,(long)5+(breite+zahl)*3*aufl,12L,
  1487.                 (long)-zahl*3*aufl,hoehe*3,(long)0xc0);
  1488.  
  1489.         }
  1490.  
  1491.         update();
  1492.  
  1493.         CloseWindow(win10);
  1494.     }
  1495.  
  1496.     if(zahl>0)
  1497.         reverse(win7,19+zahl);
  1498.     else
  1499.         reverse(win7,22-zahl);
  1500. }
  1501.  
  1502. disk()
  1503.  /* in the by this function opened window the user can change the number of
  1504.   * bitplanes to be saved as source-code, he can load a palette from an iff-
  1505.   * file or even a whole iff-picture or save his painting in the iff-format,
  1506.   * moreover he can save his painting as an image-source-code in assembler
  1507.   * or c or, if his picture-width is only 16 pixels and he chooses 2 bitpla-
  1508.   * nes, as sprite-source-code in assembler or c
  1509.   */
  1510. {
  1511.     reverse(win1,5);
  1512.     gad28.NextGadget=(bitmaps==2 && breite==16)?&gad27:NULL;
  1513.  
  1514.     nw11.Screen=scr;
  1515.     if((win11=OpenWindow(&nw11))==NULL)
  1516.         return(0);
  1517.     SetPointer(win11,mouseptr,13L,16L,-7L,-6L);
  1518.     rp11=win11->RPort;
  1519.     SetAPen(rp11,1L);
  1520.     rectangle(rp11,66,59,177,105);
  1521.     reverse(win11,32+bitmaps);
  1522.  
  1523.     do {
  1524.         while(no_msg(win11))
  1525.             WaitPort(win11->UserPort);
  1526.  
  1527.         class=msg->Class;
  1528.         code=msg->Code;
  1529.         gad=(struct Gadget *)msg->IAddress;
  1530.         ReplyMsg(msg);
  1531.  
  1532.         if(class==GADGETUP) {
  1533.             id=gad->GadgetID;
  1534.             switch(id) {
  1535.             case 26:
  1536.                 save_a_sp();
  1537.                 break;
  1538.             case 27:
  1539.                 save_c_sp();
  1540.                 break;
  1541.             case 28:
  1542.                 save_a_im();
  1543.                 break;
  1544.             case 29:
  1545.                 save_c_im();
  1546.                 break;
  1547.             case 30:
  1548.                 load_palette();
  1549.                 break;
  1550.             case 31:
  1551.                 if(!ilbmload()) alert();
  1552.                 break;
  1553.             case 32:
  1554.                 if(!ilbmsave()) alert();
  1555.                 break;
  1556.             case 33:
  1557.             case 34:
  1558.             case 35:
  1559.             case 36:
  1560.                 newbmaps(id-32);
  1561.                 break;
  1562.             }
  1563.         }
  1564.         if(class==VANILLAKEY)
  1565.             switch(code) {
  1566.             case '1':
  1567.             case '2':
  1568.             case '3':
  1569.             case '4':
  1570.                 newbmaps(code-'0');
  1571.                 break;
  1572.             case 'p':
  1573.                 load_palette();
  1574.                 break;
  1575.             case 'l':
  1576.                 if(!ilbmload()) alert();
  1577.                 break;
  1578.             case 's':
  1579.                 if(!ilbmsave()) alert();
  1580.                 break;
  1581.             case 'a':
  1582.                 save_a_im();
  1583.                 break;
  1584.             case 'c':
  1585.                 save_c_im();
  1586.                 break;
  1587.             case 'q':
  1588.                 class=CLOSEWINDOW;
  1589.                 break;
  1590.             }
  1591.     } while(class!=CLOSEWINDOW);
  1592.  
  1593.     class=0;
  1594.     CloseWindow(win11);
  1595.     reverse(win1,5);
  1596.     get_msgs();
  1597.     return(1);
  1598. }
  1599.  
  1600. newbmaps(anz)
  1601.  /* this function will be used when the user wants to change the number
  1602.   * of bitplanes to be saved; the saving of simplesprites is only possible
  1603.   * when you have 2 bitmaps; when the actual width is 16 and the number of
  1604.   * bmaps will change from or to 2 this function will also see to hide or
  1605.   * get the 'save-as-sprite' - gadgets; the int-variable bitmaps will be set
  1606.   */
  1607.     int anz;
  1608. {
  1609.     if(anz!=bitmaps) {
  1610.  
  1611.         reverse(win11,32+bitmaps);
  1612.  
  1613.         if(breite==16)
  1614.             if(bitmaps==2) {
  1615.                 gad28.NextGadget=NULL;
  1616.                 SetAPen(rp11,0L);
  1617.                 RectFill(rp11,69L,83L,174L,103L);
  1618.                 SetAPen(rp11,1L);
  1619.             } else if(anz==2) {
  1620.                 gad28.NextGadget=&gad27;
  1621.                 RefreshGList(&gad27,win11,NULL,2L);
  1622.             }
  1623.  
  1624.         bitmaps=anz;
  1625.  
  1626.         reverse(win11,32+bitmaps);
  1627.     }
  1628. }
  1629.  
  1630. load_palette()
  1631.  /* this function will ask for a filename and then load and set the color-
  1632.   * palette from the wished iff-file; if this iff-file does not contain
  1633.   * a cmap-(colormap-)chunk, the user will get informed about this;
  1634.   * remark: the extension .ilbm will be added
  1635.   */
  1636. {
  1637.     char ilbm_name[35];
  1638.     char id[5];
  1639.     long gesamt,length,gelesen;
  1640.     int done;
  1641.     unsigned char palette[32][3];
  1642.  
  1643.     reverse(win11,30);
  1644.     id[4]=0;
  1645.  
  1646.     if(getname()) {
  1647.  
  1648.         strcpy(&ilbm_name,&name);
  1649.         strcat(&ilbm_name,".ilbm");
  1650.         if((fh=Open(ilbm_name,MODE_OLDFILE))==NULL) {
  1651.             abort_info("can't open this file!",30);
  1652.             return();
  1653.         }
  1654.  
  1655.         Read(fh,id,4L);
  1656.         if(strcmp("FORM",id)) {
  1657.             abort_info("not an iff file!",30);
  1658.             return(1);
  1659.         }
  1660.         Read(fh,&gesamt,4L);
  1661.  
  1662.         gelesen=done=0;
  1663.  
  1664.         do {
  1665.             if(gelesen==gesamt) {
  1666.                 abort_info("no cmap-chunk!",30);
  1667.                 Close(fh);
  1668.                 return();
  1669.             } else {
  1670.                 Read(fh,id,4L);
  1671.                 Read(fh,&length,4L);
  1672.                 gelesen+=length+8;
  1673.  
  1674.                 if(strcmp("CMAP",id))
  1675.                     Seek(fh,length,OFFSET_CURRENT);
  1676.                 else
  1677.                     done=1;
  1678.             }
  1679.         } while(!done);
  1680.  
  1681.         Read(fh,palette[0],length);
  1682.         for(i=0;i<length/3;i++)
  1683.             paletteu[i]=(palette[i][0]<<4)+palette[i][1]+(palette[i][2]>>4);
  1684.         LoadRGB4(&scr->ViewPort,paletteu,length/3);
  1685.  
  1686.         Close(fh);
  1687.     }
  1688.  
  1689.     reverse(win11,30);
  1690. }
  1691.  
  1692. ilbmload()
  1693.  /* this function will ask the user for a filename and then load and display
  1694.   * the wished picture;
  1695.   * remark: the picture can only be loaded when it has the same width,
  1696.   *         height and depth as actually set
  1697.   * remark: the undo-picture gets lost
  1698.   * remark: the extension .ilbm will be added
  1699.   */
  1700. {
  1701.     char ilbm_name[35];
  1702.     char id[5];
  1703.     struct bmhd {
  1704.         UWORD width,height;
  1705.         UWORD x,y;
  1706.         UBYTE planes;
  1707.         UBYTE masking;
  1708.         UBYTE compr;
  1709.         UBYTE nop;
  1710.         UWORD transparent;
  1711.         UBYTE xprop,yprop;
  1712.         WORD pagewidth,pageheight;
  1713.     } bmhd;
  1714.     long length;
  1715.     unsigned char palette[32][3];
  1716.     UWORD col[16];
  1717.     long offset;
  1718.  
  1719.     reverse(win11,31);
  1720.     for(i=0;i<bitmaps;i++)
  1721.         bmap.Planes[i]=NULL;
  1722.     id[4]=0;
  1723.  
  1724.     if(getname()) {
  1725.  
  1726.         strcpy(&ilbm_name,&name);
  1727.         strcat(&ilbm_name,".ilbm");
  1728.         if((fh=Open(ilbm_name,MODE_OLDFILE))==NULL) {
  1729.             abort_info("can't open this file!",31);
  1730.             return(1);
  1731.         }
  1732.  
  1733.         Read(fh,id,4L);
  1734.         if(strcmp("FORM",id)) {
  1735.             abort_info("not an iff file!",31);
  1736.             return(1);
  1737.         }
  1738.         Seek(fh,4L,OFFSET_CURRENT);
  1739.  
  1740.         Read(fh,id,4L);
  1741.         if(strcmp("ILBM",id)) {
  1742.             abort_info("not an ilbm file!",31);
  1743.             return(1);
  1744.         }
  1745.  
  1746.         Read(fh,id,4L);
  1747.         if(strcmp("BMHD",id)) {
  1748.             abort_info("no bitmap-header!",31);
  1749.             return(1);
  1750.         }
  1751.         Seek(fh,4L,OFFSET_CURRENT);
  1752.  
  1753.         Read(fh,&bmhd,20L);
  1754.         if(bmhd.width!=breite) {
  1755.             abort_info("wrong picture width!",31);
  1756.             return(1);
  1757.         }
  1758.         if(bmhd.height!=hoehe) {
  1759.             abort_info("wrong picture height!",31);
  1760.             return(1);
  1761.         }
  1762.         if(bmhd.planes!=bitmaps) {
  1763.             abort_info("wrong picture depth!",31);
  1764.             return(1);
  1765.         }
  1766.         if(bmhd.masking!=0) {
  1767.             abort_info("wrong masking byte!",31);
  1768.             return(1);
  1769.         }
  1770.         if(bmhd.compr!=0) {
  1771.             abort_info("picture data compressed!",31);
  1772.             return(1);
  1773.         }
  1774.  
  1775.         Read(fh,id,4L);
  1776.         if(strcmp("CMAP",id)) {
  1777.             abort_info("no color-map!",31);
  1778.             return(1);
  1779.         }
  1780.         Read(fh,&length,4L);
  1781.         Read(fh,palette[0],length);
  1782.         for(i=0;i<16;i++)
  1783.             col[i]=(palette[i][0]<<4)+palette[i][1]+(palette[i][2]>>4);
  1784.  
  1785.         Read(fh,id,4L);
  1786.         if(strcmp("BODY",id)) {
  1787.             abort_info("no body-chunk!",31);
  1788.             return(1);
  1789.         }
  1790.         Seek(fh,4L,OFFSET_CURRENT);
  1791.  
  1792.         InitBitMap(&bmap,(long)bmhd.planes,
  1793.             (long)bmhd.width,(long)bmhd.height);
  1794.         for(i=0;i<bmhd.planes;i++)
  1795.             if((bmap.Planes[i]=AllocRaster((long)bmhd.width,
  1796.                 (long)bmhd.height))==NULL) {
  1797.                 for(j=0;j<i;j++)
  1798.                     FreeRaster(bmap.Planes[j],
  1799.                         (long)bmhd.width,(long)bmhd.height);
  1800.                 reverse(win11,31);
  1801.                 return(0);
  1802.             }
  1803.  
  1804.         offset=0;
  1805.         for(i=bmap.Rows-1;i>=0;i--) {
  1806.             for(j=0;j<bitmaps;j++)
  1807.                 Read(fh,bmap.Planes[j]+offset,(long)bmap.BytesPerRow);
  1808.             offset+=bmap.BytesPerRow;
  1809.         }
  1810.  
  1811.         Close(fh);
  1812.  
  1813.         if(length>48) length=48;
  1814.         for(i=0;i<length/3;i++)
  1815.             paletteu[i]=col[i];
  1816.         LoadRGB4(&scr->ViewPort,paletteu,length/3);
  1817.  
  1818.         if(aufl==1)
  1819.             BltBitMapRastPort(&bmap,0L,0L,rp3,4L,11L,(long)bmhd.width,
  1820.                 (long)bmhd.height,(long)0xc0);
  1821.         else
  1822.             for(i=0;i<bmhd.width;i++) {
  1823.                 BltBitMapRastPort(&bmap,(long)i,0L,rp3,(long)4+i*2,11L,
  1824.                     1L,(long)bmhd.height,(long)0xc0);
  1825.                 BltBitMapRastPort(&bmap,(long)i,0L,rp3,(long)5+i*2,11L,
  1826.                     1L,(long)bmhd.height,(long)0xc0);
  1827.             }
  1828.  
  1829.         for(i=0;i<bmhd.planes;i++)
  1830.             FreeRaster(bmap.Planes[i],(long)bmhd.width,(long)bmhd.height);
  1831.  
  1832.         if(anzeigen)
  1833.             ClipBlit(rp3,4L,11L,rp8,5L,12L,breite*aufl,hoehe,(long)0xc0);
  1834.         update();
  1835.         erase();
  1836.     }
  1837.  
  1838.     reverse(win11,31);
  1839.     return(1);
  1840. }
  1841.  
  1842. ilbmsave()
  1843.  /* this function will ask the user for a filename and then save the actual
  1844.   * picture as an iff-file with the wished name;
  1845.   * remark: the extension .ilbm will be added
  1846.   */
  1847. {
  1848.     char ilbm_name[35];
  1849.     struct bmhd {
  1850.         UWORD width,height;
  1851.         UWORD x,y;
  1852.         UBYTE planes;
  1853.         UBYTE masking;
  1854.         UBYTE compr;
  1855.         UBYTE nop;
  1856.         UWORD transparent;
  1857.         UBYTE xprop,yprop;
  1858.         WORD pagewidth,pageheight;
  1859.     } bmhd;
  1860.     char b;
  1861.     int w;
  1862.     long l,offset;
  1863.  
  1864.     reverse(win11,32);
  1865.     for(i=0;i<bitmaps;i++)
  1866.         bmap.Planes[i]=NULL;
  1867.  
  1868.     if(getname()) {
  1869.         InitBitMap(&bmap,(long)bitmaps,breite,hoehe);
  1870.         for(i=0;i<bitmaps;i++)
  1871.             if((bmap.Planes[i]=AllocRaster(breite,hoehe))==NULL) {
  1872.                 for(j=0;j<i;j++)
  1873.                     FreeRaster(bmap.Planes[j],breite,hoehe);
  1874.                 reverse(win11,32);
  1875.                 return(0);
  1876.             }
  1877.  
  1878.         nw12.Screen=scr;
  1879.         nw12.BitMap=&bmap;
  1880.         if((win12=OpenWindow(&nw12))==NULL) {
  1881.             close_ilbm();
  1882.             reverse(win11,32);
  1883.             return(0);
  1884.         }
  1885.         rp12=win12->RPort;
  1886.  
  1887.         if(aufl==1)
  1888.             ClipBlit(rp3,4L,11L,rp12,0L,0L,breite,hoehe,(long)0xc0);
  1889.         else
  1890.             for(i=0;i<breite;i++)
  1891.                 ClipBlit(rp3,(long)4+i*2,11L,rp12,(long)i,0L,
  1892.                     1L,hoehe,(long)0xc0);
  1893.  
  1894.         ClipBlit(rp12,0L,0L,rp12,0L,0L,breite,hoehe,(long)0xc0);
  1895.  
  1896.         strcpy(&ilbm_name,&name);
  1897.         strcat(&ilbm_name,".ilbm");
  1898.         if((fh=Open(ilbm_name,MODE_NEWFILE))==NULL) {
  1899.             close_ilbm();
  1900.             reverse(win11,32);
  1901.             return(0);
  1902.         }
  1903.  
  1904.         Write(fh,"FORM",4L);
  1905.         l=4+28+104+8+bmap.BytesPerRow*bmap.Rows*bmap.Depth;
  1906.         Write(fh,&l,4L);
  1907.         Write(fh,"ILBM",4L);
  1908.  
  1909.         Write(fh,"BMHD",4L);
  1910.         l=20;
  1911.         Write(fh,&l,4L);
  1912.  
  1913.         bmhd.width=breite;
  1914.         bmhd.height=hoehe;
  1915.         bmhd.x=bmhd.y=0;
  1916.         bmhd.planes=bitmaps;
  1917.         bmhd.masking=bmhd.compr=bmhd.nop=0;
  1918.         bmhd.transparent=0;
  1919.         bmhd.xprop=aufl==1?5:10;
  1920.         bmhd.yprop=11;
  1921.         bmhd.pagewidth=aufl==1?640:320;
  1922.         bmhd.pageheight=200;
  1923.         Write(fh,&bmhd,20L);
  1924.  
  1925.         Write(fh,"CMAP",4L);
  1926.         l=96;
  1927.         Write(fh,&l,4L);
  1928.         for(i=0;i<16;i++) {
  1929.             b=((paletteu[i] & 0xf00)>>4);
  1930.             Write(fh,&b,1L);
  1931.             b=(paletteu[i] & 0x0f0);
  1932.             Write(fh,&b,1L);
  1933.             b=((paletteu[i] & 0x00f)<<4);
  1934.             Write(fh,&b,1L);
  1935.         }
  1936.         b=0;
  1937.         for(i=16;i<32;i++)
  1938.             for(j=0;j<3;j++)
  1939.                 Write(fh,&b,1L);
  1940.  
  1941.         Write(fh,"BODY",4L);
  1942.         l=bmap.BytesPerRow*bmap.Rows*bmap.Depth;
  1943.         Write(fh,&l,4L);
  1944.  
  1945.         offset=0;
  1946.         for(i=bmap.Rows-1;i>=0;i--) {
  1947.             for(j=0;j<bitmaps;j++)
  1948.                 Write(fh,bmap.Planes[j]+offset,(long)bmap.BytesPerRow);
  1949.             offset+=bmap.BytesPerRow;
  1950.         }
  1951.  
  1952.         close_ilbm();
  1953.     }
  1954.  
  1955.     reverse(win11,32);
  1956.     return(1);
  1957. }
  1958.  
  1959. close_ilbm()
  1960.  /* this function will help to make the function ilbmsave shorter; it is
  1961.   * closing everything ilbmsave could have opened and setting the pointer
  1962.   * belonging to this things to null
  1963.   */
  1964. {
  1965.     if(fh) Close(fh);
  1966.     if(win12) CloseWindow(win12);
  1967.     for(i=0;i<bitmaps;i++)
  1968.         if(bmap.Planes[i])
  1969.             FreeRaster(bmap.Planes[i],breite,hoehe);
  1970.  
  1971.     fh=win12=NULL;
  1972. }
  1973.  
  1974. getname()
  1975.  /* this function is needed to ask the user for a file name (to load or
  1976.   * save); it opens a window and waits till the user finishes
  1977.   */
  1978. {
  1979.     nw13.Screen=scr;
  1980.     if((win13=OpenWindow(&nw13))==NULL) {
  1981.         alert();
  1982.         return(0);
  1983.     }
  1984.     SetPointer(win13,mouseptr,13L,16L,-7L,-6L);
  1985.     rp13=win13->RPort;
  1986.     SetAPen(rp13,1L);
  1987.  
  1988.     text(rp13,14,14,"name :");
  1989.     ActivateGadget(&gad37,win13,NULL);
  1990.  
  1991.     while(no_msg(win13))
  1992.         WaitPort(win13->UserPort);
  1993.  
  1994.     id=((struct Gadget *)msg->IAddress)->GadgetID;
  1995.     ReplyMsg(msg);
  1996.  
  1997.     CloseWindow(win13);
  1998.     return(id==37 || id==38);
  1999. }
  2000.  
  2001. abort_info(str,nr)
  2002.  /* if any of the disk-functions has to be aborted, it calls this function
  2003.   * which displays the reason for aborting and reverses the gadget corres-
  2004.   * ponding to the function; at least the file will be closed if it was
  2005.   * open; the reason-text and the gadget-id are passed to this function as
  2006.   * arguments
  2007.   */
  2008.     char *str;
  2009.     int nr;
  2010. {
  2011.     nw15.Screen=scr;
  2012.     if((win15=OpenWindow(&nw15))==NULL) {
  2013.         alert();
  2014.         return();
  2015.     }
  2016.     SetPointer(win15,mouseptr,13L,16L,-7L,-6L);
  2017.     rp15=win15->RPort;
  2018.     SetAPen(rp15,2L);
  2019.     text(rp15,150-strlen(str)*4,15,str);
  2020.  
  2021.     WaitPort(win15->UserPort);
  2022.     CloseWindow(win15);
  2023.  
  2024.     reverse(win11,nr);
  2025.     if(fh) Close(fh);
  2026. }
  2027.  
  2028. compute()
  2029.  /* this function is computing the source-code-words to be saved; every
  2030.   * of the save-as-source-functions calls this function before saving
  2031.   */
  2032. {
  2033.     for(i=0;i<44;i++)
  2034.         for(j=0;j<hoehe;j++)
  2035.             for(k=0;k<4;k++)
  2036.                 src[i][j][k]=0;
  2037.  
  2038.     for(i=0;i<hoehe;i++)
  2039.         for(j=0;j<bitmaps;j++)
  2040.             for(k=0;k<breite;k++)
  2041.                 if(ReadPixel(rp3,(long)4+k*aufl,(long)11+i)&(1<<j))
  2042.                     src[(j*11)+(k>>4)][i][(k>>2)&0x03]|=(1<<(3-(k&0x03)));
  2043.  
  2044.     for(i=0;i<44;i++)
  2045.         for(j=0;j<hoehe;j++)
  2046.             for(k=0;k<4;k++) {
  2047.                 src[i][j][k]+=48;
  2048.                 if(src[i][j][k]>57)
  2049.                     src[i][j][k]+=39;
  2050.             }
  2051. }
  2052.  
  2053. save_a_im()
  2054.  /* this function will ask the user for a filename and then save the picture
  2055.   * as assembler-image-source-code with the image-structure;
  2056.   * remark: the extension .asm will be added
  2057.   */
  2058. {
  2059.     char asm_name[34],data[4],newline=10;
  2060.     static unsigned char number[4][3]={"1st","2nd","3rd","4th"};
  2061.     int num,nextline;
  2062.  
  2063.     reverse(win11,28);
  2064.  
  2065.     if(getname()) {
  2066.  
  2067.         strcpy(&asm_name,&name);
  2068.         strcat(&asm_name,".asm");
  2069.         if((fh=Open(asm_name,MODE_NEWFILE))==NULL) {
  2070.             abort_info("can't open this file!",28);
  2071.             return();
  2072.         }
  2073.  
  2074.         compute();
  2075.  
  2076.         Write(fh,name,(long)strlen(name));
  2077.         Write(fh,"data:",5L);
  2078.         Write(fh,&newline,1L);
  2079.  
  2080.         nextline=breite>128?8:(breite-1)/16+1;
  2081.  
  2082.         for(i=0;i<bitmaps;i++) {
  2083.             Write(fh,"; ",2L);
  2084.             Write(fh,number[i],3L);
  2085.             Write(fh," bitplane:",10L);
  2086.  
  2087.             for(j=0;j<hoehe;j++) {
  2088.                 if(j==0 || num==nextline) {
  2089.                     Write(fh,&newline,1L);
  2090.                     Write(fh,"        dc.w    $",17L);
  2091.                     num=0;
  2092.                 } else
  2093.                     Write(fh,", $",3L);
  2094.                 num++;
  2095.                 Write(fh,src[i*11][j],4L);
  2096.  
  2097.                 for(k=1;k<=11;k++)
  2098.                     if(breite>k*16) {
  2099.                         if(num==nextline) {
  2100.                             Write(fh,&newline,1L);
  2101.                             Write(fh,"        dc.w    $",17L);
  2102.                             num=0;
  2103.                         } else
  2104.                             Write(fh,", $",3L);
  2105.                         num++;
  2106.                         Write(fh,src[i*11+k][j],4L);
  2107.                     }
  2108.  
  2109.                 if(j==hoehe-1) {
  2110.                     Write(fh,&newline,1L);
  2111.                     if(i==bitmaps-1)
  2112.                         Write(fh,&newline,1L);
  2113.                 }
  2114.  
  2115.             }
  2116.         }
  2117.  
  2118.         Write(fh,name,(long)strlen(name));
  2119.         Write(fh,":",1L);
  2120.         Write(fh,&newline,1L);
  2121.         Write(fh,"; struct Image:",15L);
  2122.         Write(fh,&newline,1L);
  2123.         Write(fh,"        dc.w 0",14L);
  2124.         Write(fh,&newline,1L);
  2125.         Write(fh,"        dc.w 0",14L);
  2126.         Write(fh,&newline,1L);
  2127.         ltoa(breite,data);
  2128.         Write(fh,"        dc.w ",13L);
  2129.         Write(fh,data,(long)strlen(data));
  2130.         Write(fh,&newline,1L);
  2131.         ltoa(hoehe,data);
  2132.         Write(fh,"        dc.w ",13L);
  2133.         Write(fh,data,(long)strlen(data));
  2134.         Write(fh,&newline,1L);
  2135.         ltoa((long)bitmaps,data);
  2136.         Write(fh,"        dc.w ",13L);
  2137.         Write(fh,data,(long)strlen(data));
  2138.         Write(fh,&newline,1L);
  2139.         Write(fh,"        dc.l ",13L);
  2140.         Write(fh,name,(long)strlen(name));
  2141.         Write(fh,"data",4L);
  2142.         Write(fh,&newline,1L);
  2143.         ltoa((long)(1<<bitmaps)-1,data);
  2144.         Write(fh,"        dc.b ",13L);
  2145.         Write(fh,data,(long)strlen(data));
  2146.         Write(fh,&newline,1L);
  2147.         Write(fh,"        dc.b 0",14L);
  2148.         Write(fh,&newline,1L);
  2149.         Write(fh,"        dc.l 0",14L);
  2150.         Write(fh,&newline,1L);
  2151.         Write(fh,&newline,1L);
  2152.  
  2153.         Close(fh);
  2154.     }
  2155.  
  2156.     reverse(win11,28);
  2157. }
  2158.  
  2159. save_c_im()
  2160.  /* this function will ask the user for a filename and then save the picture
  2161.   * as c-image-source-code with the image-structure;
  2162.   * remark: the extension .c will be added
  2163.   */
  2164. {
  2165.     char c_name[32],data[4],newline=10;
  2166.     static unsigned char number[4][3]={"1st","2nd","3rd","4th"};
  2167.     int num,nextline;
  2168.  
  2169.     reverse(win11,29);
  2170.  
  2171.     if(getname()) {
  2172.  
  2173.         strcpy(&c_name,&name);
  2174.         strcat(&c_name,".c");
  2175.         if((fh=Open(c_name,MODE_NEWFILE))==NULL) {
  2176.             abort_info("can't open this file!",29);
  2177.             return();
  2178.         }
  2179.  
  2180.         compute();
  2181.  
  2182.         Write(fh,"USHORT ",7L);
  2183.         Write(fh,name,(long)strlen(name));
  2184.         Write(fh,"data[] = {",10L);
  2185.         Write(fh,&newline,1L);
  2186.  
  2187.         nextline=breite>128?8:(breite-1)/16+1;
  2188.  
  2189.         for(i=0;i<bitmaps;i++) {
  2190.             Write(fh,"         /* ",12L);
  2191.             Write(fh,number[i],3L);
  2192.             Write(fh," bitplane */",12L);
  2193.  
  2194.             for(j=0;j<hoehe;j++) {
  2195.                 if(j==0 || num==nextline) {
  2196.                     if(!(j==hoehe && breite<=(k+1)*16))
  2197.                         if(j!=0)
  2198.                             Write(fh,",",1L);
  2199.                     Write(fh,&newline,1L);
  2200.                     Write(fh,"        0x",10L);
  2201.                     num=0;
  2202.                 } else
  2203.                     Write(fh,", 0x",4L);
  2204.                 num++;
  2205.                 Write(fh,src[i*11][j],4L);
  2206.  
  2207.                 for(k=1;k<=11;k++)
  2208.                     if(breite>k*16) {
  2209.                         if(num==nextline) {
  2210.                             if(!(j==hoehe-1 && breite<=(k+1)*16))
  2211.                                 Write(fh,",",1L);
  2212.                             Write(fh,&newline,1L);
  2213.                             Write(fh,"        0x",10L);
  2214.                             num=0;
  2215.                         } else
  2216.                             Write(fh,", 0x",4L);
  2217.                         num++;
  2218.                         Write(fh,src[i*11+k][j],4L);
  2219.                     }
  2220.  
  2221.                 if(j==hoehe-1) {
  2222.                     if(i==bitmaps-1) {
  2223.                         Write(fh," };",3L);
  2224.                         Write(fh,&newline,1L);
  2225.                     } else
  2226.                         Write(fh,",",1L);
  2227.                     Write(fh,&newline,1L);
  2228.                 }
  2229.  
  2230.             }
  2231.         }
  2232.  
  2233.         Write(fh,"struct Image ",13L);
  2234.         Write(fh,name,(long)strlen(name));
  2235.         Write(fh," =",2L);
  2236.         Write(fh,&newline,1L);
  2237.         Write(fh,"        { 0, 0, ",16L);
  2238.         ltoa(breite,data);
  2239.         Write(fh,data,(long)strlen(data));
  2240.         Write(fh,", ",2L);
  2241.         ltoa(hoehe,data);
  2242.         Write(fh,data,(long)strlen(data));
  2243.         Write(fh,", ",2L);
  2244.         ltoa((long)bitmaps,data);
  2245.         Write(fh,data,(long)strlen(data));
  2246.         Write(fh,", ",2L);
  2247.         Write(fh,name,(long)strlen(name));
  2248.         Write(fh,"data, ",6L);
  2249.         ltoa((long)(1<<bitmaps)-1,data);
  2250.         Write(fh,data,(long)strlen(data));
  2251.         Write(fh,", 0, NULL };",12L);
  2252.         Write(fh,&newline,1L);
  2253.         Write(fh,&newline,1L);
  2254.  
  2255.         Close(fh);
  2256.     }
  2257.  
  2258.     reverse(win11,29);
  2259. }
  2260.  
  2261. ltoa(nr,s)
  2262.  /* this function is turning a long-value to a (ascii-)c-string; i expected
  2263.   * to find it the c.lib because it's a standard c function, but i couldn't
  2264.   */
  2265.     long nr;
  2266.     char *s;
  2267. {
  2268.     int i,sign;
  2269.  
  2270.     if((sign=nr)<0)
  2271.         nr=-nr;
  2272.  
  2273.     i=0;
  2274.     do {
  2275.         s[i++]=nr%10+'0';
  2276.     } while((nr/=10)>0);
  2277.  
  2278.     if(sign<0)
  2279.         s[i++]='-';
  2280.  
  2281.     s[i]=0;
  2282.  
  2283.     rev_str(s);
  2284. }
  2285.  
  2286. rev_str(s)
  2287.  /* this function is reversing a c-string; it is used only by ltoa,
  2288.   * because ltoa cannot distinguish sides
  2289.   */
  2290.     char *s;
  2291. {
  2292.     int i,j;
  2293.     char c;
  2294.  
  2295.     for(i=0,j=strlen(s)-1;i<j;i++,j--) {
  2296.         c=s[i];
  2297.         s[i]=s[j];
  2298.         s[j]=c;
  2299.     }
  2300. }
  2301.  
  2302. save_a_sp()
  2303.  /* this function will ask the user for a filename and then save the picture
  2304.   * as assembler-sprite-source-code with the simplesprite-structure;
  2305.   * remark: the extension .asm will be added
  2306.   */
  2307. {
  2308.     char asm_name[34],data[4],newline=10;
  2309.  
  2310.     reverse(win11,26);
  2311.  
  2312.     if(getname()) {
  2313.  
  2314.         strcpy(&asm_name,&name);
  2315.         strcat(&asm_name,".asm");
  2316.         if((fh=Open(asm_name,MODE_NEWFILE))==NULL) {
  2317.             abort_info("can't open this file!",26);
  2318.             return();
  2319.         }
  2320.  
  2321.         compute();
  2322.  
  2323.         Write(fh,name,(long)strlen(name));
  2324.         Write(fh,"data:",5L);
  2325.         Write(fh,&newline,1L);
  2326.  
  2327.         Write(fh,"        dc.w 0,0",16L);
  2328.         Write(fh,&newline,1L);
  2329.         for(i=0;i<hoehe;i++) {
  2330.             Write(fh,"        dc.w $",14L);
  2331.             Write(fh,src[0][i],4L);
  2332.             Write(fh,", $",3L);
  2333.             Write(fh,src[11][i],4L);
  2334.             Write(fh,&newline,1L);
  2335.         }
  2336.         Write(fh,"        dc.w 0,0",16L);
  2337.         Write(fh,&newline,1L);
  2338.         Write(fh,&newline,1L);
  2339.  
  2340.         Write(fh,name,(long)strlen(name));
  2341.         Write(fh,":",1L);
  2342.         Write(fh,&newline,1L);
  2343.         Write(fh,"        dc.l ",13L);
  2344.         Write(fh,name,(long)strlen(name));
  2345.         Write(fh,"data",4L);
  2346.         Write(fh,&newline,1L);
  2347.         ltoa(hoehe,data);
  2348.         Write(fh,"        dc.w ",13L);
  2349.         Write(fh,data,(long)strlen(data));
  2350.         Write(fh,&newline,1L);
  2351.         Write(fh,"        dc.w 0",14L);
  2352.         Write(fh,&newline,1L);
  2353.         Write(fh,"        dc.w 0",14L);
  2354.         Write(fh,&newline,1L);
  2355.         Write(fh,"        dc.w 0",14L);
  2356.         Write(fh,&newline,1L);
  2357.         Write(fh,&newline,1L);
  2358.  
  2359.         Close(fh);
  2360.     }
  2361.  
  2362.     reverse(win11,26);
  2363. }
  2364.  
  2365. save_c_sp()
  2366.  /* this function will ask the user for a filename and then save the picture
  2367.   * as c-sprite-source-code with the simplesprite-structure;
  2368.   * remark: the extension .c will be added
  2369.   */
  2370. {
  2371.     char c_name[32],data[4],newline=10;
  2372.  
  2373.     reverse(win11,27);
  2374.  
  2375.     if(getname()) {
  2376.  
  2377.         strcpy(&c_name,&name);
  2378.         strcat(&c_name,".c");
  2379.         if((fh=Open(c_name,MODE_NEWFILE))==NULL) {
  2380.             abort_info("can't open this file!",27);
  2381.             return();
  2382.         }
  2383.  
  2384.         compute();
  2385.  
  2386.         Write(fh,"UWORD ",6L);
  2387.         Write(fh,name,(long)strlen(name));
  2388.         Write(fh,"data[] = {",10L);
  2389.         Write(fh,&newline,1L);
  2390.  
  2391.         Write(fh,"        0x0000, 0x0000,",23L);
  2392.         Write(fh,&newline,1L);
  2393.         for(i=0;i<hoehe;i++) {
  2394.             Write(fh,"        0x",10L);
  2395.             Write(fh,src[0][i],4L);
  2396.             Write(fh,", 0x",4L);
  2397.             Write(fh,src[11][i],4L);
  2398.             Write(fh,",",1L);
  2399.             Write(fh,&newline,1L);
  2400.         }
  2401.         Write(fh,"        0x0000, 0x0000 };",25L);
  2402.         Write(fh,&newline,1L);
  2403.         Write(fh,&newline,1L);
  2404.  
  2405.         Write(fh,"struct SimpleSprite ",20L);
  2406.         Write(fh,name,(long)strlen(name));
  2407.         Write(fh," =",2L);
  2408.         Write(fh,&newline,1L);
  2409.         Write(fh,"        { ",10L);
  2410.         Write(fh,name,(long)strlen(name));
  2411.         Write(fh,"data, ",6L);
  2412.         ltoa(hoehe,data);
  2413.         Write(fh,data,(long)strlen(data));
  2414.         Write(fh,", 0, 0, 0 };",12L);
  2415.         Write(fh,&newline,1L);
  2416.         Write(fh,&newline,1L);
  2417.  
  2418.         Close(fh);
  2419.     }
  2420.  
  2421.     reverse(win11,27);
  2422. }
  2423.  
  2424. prefs()
  2425.  /* in the from this function opened window the user can change between the
  2426.   * hires and the normal display mode (where the pixel width is doubled), he
  2427.   * can also change the width and the height of the picture
  2428.   */
  2429. {
  2430.     int old_aufl;
  2431.     long old_breite,old_hoehe;
  2432.     char brei[4],hoe[3];
  2433.     int breit,hoeh;
  2434.  
  2435.     reverse(win1,7);
  2436.  
  2437.     old_aufl=aufl;
  2438.     old_breite=breite;
  2439.     old_hoehe=hoehe;
  2440.  
  2441.     brei[3]=hoe[2]=0;
  2442.  
  2443.     prop1.HorizBody=aufl==1?0x018a:0x0315;
  2444.     prop1.HorizPot=(USHORT)breite*prop1.HorizBody-1;
  2445.     prop2.HorizPot=(USHORT)hoehe*0x0469-1;
  2446.  
  2447.     nw16.Screen=scr;
  2448.     if((win16=OpenWindow(&nw16))==NULL) {
  2449.         reverse(win1,7);
  2450.         return(0);
  2451.     }
  2452.  
  2453.     SetPointer(win16,mouseptr,13L,16L,-7L,-6L);
  2454.     rp16=win16->RPort;
  2455.     SetAPen(rp16,1L);
  2456.     rectangle(rp16,21,75,234,90);
  2457.     reverse(win16,42+aufl);
  2458.  
  2459.     do {
  2460.         while(no_msg(win16))
  2461.             WaitPort(win16->UserPort);
  2462.  
  2463.         class=msg->Class;
  2464.         code=msg->Code;
  2465.         gad=(struct Gadget *)msg->IAddress;
  2466.         ReplyMsg(msg);
  2467.  
  2468.         if(class==INTUITICKS) {
  2469.             breite=prop1.HorizPot/prop1.HorizBody+1;
  2470.             hoehe=prop2.HorizPot/prop2.HorizBody+1;
  2471.  
  2472.             if(aufl==1)
  2473.                 breite=breite>166?166:breite;
  2474.             else
  2475.                 breite=breite>83?83:breite;
  2476.             hoehe=hoehe>58?58:hoehe;
  2477.  
  2478.             ltoa(breite,brei);
  2479.             ltoa(hoehe,hoe);
  2480.  
  2481.             SetAPen(rp16,0L);
  2482.             RectFill(rp16,220L,40L,243L,47L);
  2483.             SetAPen(rp16,1L);
  2484.             text(rp16,220,40,brei);
  2485.  
  2486.             SetAPen(rp16,0L);
  2487.             RectFill(rp16,220L,62L,235L,69L);
  2488.             SetAPen(rp16,1L);
  2489.             text(rp16,220,62,hoe);
  2490.         }
  2491.         if(class==CLOSEWINDOW) {
  2492.             aufl=old_aufl;
  2493.             breite=old_breite;
  2494.             hoehe=old_hoehe;
  2495.         }
  2496.         if(class==GADGETUP) {
  2497.             id=gad->GadgetID;
  2498.             switch(id) {
  2499.             case 43:
  2500.                 if(aufl==2) {
  2501.                     aufl=1;
  2502.                     reverse(win16,43);
  2503.                     reverse(win16,44);
  2504.                     breite*=2;
  2505.  
  2506.                     prop1.HorizBody=0x018a;
  2507.                     prop1.HorizPot=(USHORT)breite*prop1.HorizBody-1;
  2508.                     RefreshGList(&gad45,win16,NULL,1L);
  2509.                 }
  2510.                 break;
  2511.             case 44:
  2512.                 if(aufl==1) {
  2513.                     aufl=2;
  2514.                     reverse(win16,43);
  2515.                     reverse(win16,44);
  2516.                     breite/=2;
  2517.  
  2518.                     prop1.HorizBody=0x0315;
  2519.                     prop1.HorizPot=(USHORT)breite*prop1.HorizBody-1;
  2520.                     RefreshGList(&gad45,win16,NULL,1L);
  2521.                 }
  2522.                 break;
  2523.             case 47:
  2524.                 SetAPen(rp1,0L);
  2525.                 RectFill(rp1,(long)xmin-1,(long)ymin-1,
  2526.                     (long)xmax+1,(long)ymax+1);
  2527.  
  2528.                 SetAPen(rp3,0L);
  2529.                 RectFill(rp3,4L,11L,
  2530.                     (long)3+old_breite*aufl,(long)10+old_hoehe);
  2531.  
  2532.                 if(anzeigen) {
  2533.                     SetAPen(rp8,0L);
  2534.                     RectFill(rp8,4L,11L,5+old_breite*old_aufl,12+old_hoehe);
  2535.                     breit=breite;
  2536.                     hoeh=hoehe;
  2537.                     SetAPen(rp8,1L);
  2538.                     rectangle(rp8,4,11,5+breit*aufl,12+hoeh);
  2539.                 }
  2540.                 xmax=4+breite*3*aufl;
  2541.                 ymax=11+hoehe*3;
  2542.  
  2543.                 SetAPen(rp1,1L);
  2544.                 rectangle(rp1,xmin-1,ymin-1,xmax+1,ymax+1);
  2545.  
  2546.                 class=CLOSEWINDOW;
  2547.                 break;
  2548.             case 48:
  2549.                 aufl=old_aufl;
  2550.                 breite=old_breite;
  2551.                 hoehe=old_hoehe;
  2552.                 class=CLOSEWINDOW;
  2553.                 break;
  2554.             }
  2555.         }
  2556.         if(class==VANILLAKEY)
  2557.             if(code=='q') {
  2558.                 aufl=old_aufl;
  2559.                 breite=old_breite;
  2560.                 hoehe=old_hoehe;
  2561.                 class=CLOSEWINDOW;
  2562.             }
  2563.  
  2564.     } while(class!=CLOSEWINDOW);
  2565.  
  2566.     class=0;
  2567.     CloseWindow(win16);
  2568.     reverse(win1,7);
  2569.     get_msgs();
  2570.     return(1);
  2571. }
  2572.  
  2573. colors()
  2574.  /* in the from this function opened window the user can edit the colors;
  2575.   * he can then accept his new palette, take the palette before or simple
  2576.   * reset the palette to the palette which was at the beginning of the
  2577.   * program
  2578.   */
  2579. {
  2580.     UWORD palettes[16];
  2581.     char r[2],g[2],b[2];
  2582.     USHORT re,gr,bl;
  2583.     int col;
  2584.  
  2585.     reverse(win1,6);
  2586.  
  2587.     for(i=0;i<16;i++)
  2588.         palettes[i]=paletteu[i];
  2589.  
  2590.     r[1]=g[1]=b[1]=0;
  2591.  
  2592.     prop3.HorizPot=((paletteu[colorl]>>8)&0xf)*0x1000+0x0800;
  2593.     prop4.HorizPot=((paletteu[colorl]>>4)&0xf)*0x1000+0x0800;
  2594.     prop5.HorizPot=(paletteu[colorl]&0xf)*0x1000+0x0800;
  2595.  
  2596.     nw17.Screen=scr;
  2597.     if((win17=OpenWindow(&nw17))==NULL) {
  2598.         reverse(win1,6);
  2599.         return(0);
  2600.     }
  2601.  
  2602.     SetPointer(win17,mouseptr,13L,16L,-7L,-6L);
  2603.     rp17=win17->RPort;
  2604.     SetAPen(rp17,1L);
  2605.     rectangle(rp17,12,15,117,56);
  2606.  
  2607.     do {
  2608.         while(no_msg(win17))
  2609.             WaitPort(win17->UserPort);
  2610.  
  2611.         class=msg->Class;
  2612.         code=msg->Code;
  2613.         gad=(struct Gadget *)msg->IAddress;
  2614.         ReplyMsg(msg);
  2615.  
  2616.         if(class==INTUITICKS) {
  2617.             re=prop3.HorizPot/0x1000;
  2618.             gr=prop4.HorizPot/0x1000;
  2619.             bl=prop5.HorizPot/0x1000;
  2620.  
  2621.             paletteu[colorl]=(re<<8)+(gr<<4)+bl;
  2622.             SetRGB4(vp,(long)colorl,(long)re,(long)gr,(long)bl);
  2623.  
  2624.             r[0]=re>9?re+'a'-10:re+'0';
  2625.             g[0]=gr>9?gr+'a'-10:gr+'0';
  2626.             b[0]=bl>9?bl+'a'-10:bl+'0';
  2627.  
  2628.             SetAPen(rp17,0L);
  2629.             RectFill(rp17,298L,18L,305L,25L);
  2630.             SetAPen(rp17,1L);
  2631.             text(rp17,298,18,r);
  2632.  
  2633.             SetAPen(rp17,0L);
  2634.             RectFill(rp17,298L,31L,305L,38L);
  2635.             SetAPen(rp17,1L);
  2636.             text(rp17,298,31,g);
  2637.  
  2638.             SetAPen(rp17,0L);
  2639.             RectFill(rp17,298L,44L,305L,51L);
  2640.             SetAPen(rp17,1L);
  2641.             text(rp17,298,44,b);
  2642.         }
  2643.         if(class==GADGETUP) { ;
  2644.             id=gad->GadgetID;
  2645.             switch(id) {
  2646.             case 49:
  2647.                 class=CLOSEWINDOW;
  2648.                 break;
  2649.             case 50:
  2650.                 for(i=0;i<16;i++)
  2651.                     paletteu[i]=palettes[i];
  2652.                 LoadRGB4(vp,paletteu,16L);
  2653.                 class=CLOSEWINDOW;
  2654.                 break;
  2655.             case 51:
  2656.                 for(i=0;i<16;i++)
  2657.                     paletteu[i]=paletteb[i];
  2658.                 LoadRGB4(vp,paletteu,16L);
  2659.                 class=CLOSEWINDOW;
  2660.                 break;
  2661.             }
  2662.         }
  2663.         if(class==VANILLAKEY)
  2664.             switch(code) {
  2665.             case 'b':
  2666.                 col=(colorl-1)&0xf;
  2667.                 new_color('l',col);
  2668.                 prop3.HorizPot=((paletteu[colorl]>>8)&0xf)*0x1000+0x0800;
  2669.                 prop4.HorizPot=((paletteu[colorl]>>4)&0xf)*0x1000+0x0800;
  2670.                 prop5.HorizPot=(paletteu[colorl]&0xf)*0x1000+0x0800;
  2671.                 RefreshGList(&gad54,win17,NULL,3L);
  2672.                 break;
  2673.             case 'n':
  2674.                 col=(colorl+1)&0xf;
  2675.                 new_color('l',col);
  2676.                 prop3.HorizPot=((paletteu[colorl]>>8)&0xf)*0x1000+0x0800;
  2677.                 prop4.HorizPot=((paletteu[colorl]>>4)&0xf)*0x1000+0x0800;
  2678.                 prop5.HorizPot=(paletteu[colorl]&0xf)*0x1000+0x0800;
  2679.                 RefreshGList(&gad54,win17,NULL,3L);
  2680.                 break;
  2681.             case 'q':
  2682.                 class=CLOSEWINDOW;
  2683.                 break;
  2684.             }
  2685.  
  2686.     } while(class!=CLOSEWINDOW);
  2687.  
  2688.     class=0;
  2689.     CloseWindow(win17);
  2690.     reverse(win1,6);
  2691.     get_msgs();
  2692.     return(1);
  2693. }
  2694.